Skip to content

Commit 1d37eef

Browse files
committed
refactor: ♻️ move Issuer type to lib.rs
1 parent 6ba12c4 commit 1d37eef

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

test-certs/src/generation.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
use std::sync::Arc;
2-
31
use rcgen::{
42
BasicConstraints, CertificateParams, DistinguishedName, DnType, ExtendedKeyUsagePurpose, IsCa,
53
KeyPair, KeyUsagePurpose,
64
};
75

86
use crate::{
9-
Certificate, Error,
7+
Certificate, Error, Issuer,
108
configuration::certificates::{
119
CertificateAuthorityConfiguration, CertificateType, ClientConfiguration,
1210
ServerConfiguration, SubjectAlternativeNames,
1311
},
1412
};
1513

16-
/// Type alias to make code more readable.
17-
type Issuer = Arc<Certificate>;
18-
1914
/// Extension trait to convert [`CertificateType`] to [`Certificate`].
2015
// NOTE: Instead of a trait use actual types?
2116
pub trait CertificateGenerator {

test-certs/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ pub enum Error {
3333
#[error("Multiple errors occurred")]
3434
ErrorCollection(Vec<Error>),
3535
}
36+
/// Type alias to make code more readable.
37+
type Issuer = Arc<Certificate>;
3638

3739
/// A pair of a certificate and the corresponding private key.
3840
pub struct Certificate {
3941
certificate: rcgen::Certificate,
4042
key: KeyPair,
4143
export_key: bool,
4244
name: String,
43-
issuer: Option<Arc<Certificate>>,
45+
issuer: Option<Issuer>,
4446
}
4547

4648
impl PartialEq for Certificate {
@@ -73,6 +75,7 @@ impl Certificate {
7375
if current_issuer.issuer.is_none() {
7476
// NOTE: If we have no issuer anymore we are at top level
7577
// and do not include the root ca.
78+
// See [RFC 5246](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.2)
7679
break;
7780
}
7881
cert.write_fmt(format_args!("{}", current_issuer.certificate.pem()))
@@ -122,7 +125,7 @@ pub fn generate(certificate_config: &CertificateRoot) -> Result<Vec<Arc<Certific
122125
fn generate_certificates(
123126
name: &str,
124127
config: &CertificateType,
125-
issuer: Option<&Arc<Certificate>>,
128+
issuer: Option<&Issuer>,
126129
) -> Result<Vec<Arc<Certificate>>, Error> {
127130
let mut result = vec![];
128131
let issuer = config.build(name, issuer)?;

0 commit comments

Comments
 (0)