Skip to content

Commit 2e18fbb

Browse files
committed
fixup! Allow multiple issuer items of the same kind
1 parent 0ecfc1b commit 2e18fbb

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

rcgen/src/certificate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl CertificateParams {
608608
let der = subject_key.sign_der(|writer| {
609609
// Write version
610610
writer.next().write_u8(0);
611-
write_distinguished_name(writer.next(), distinguished_name.clone());
611+
write_distinguished_name(writer.next(), distinguished_name);
612612
serialize_public_key_der(subject_key, writer.next());
613613

614614
// According to the spec in RFC 2986, even if attributes are empty we need the empty attribute tag
@@ -670,7 +670,7 @@ impl CertificateParams {
670670
// Write signature algorithm
671671
issuer.key_pair.alg.write_alg_ident(writer.next());
672672
// Write issuer name
673-
write_distinguished_name(writer.next(), issuer.distinguished_name.clone());
673+
write_distinguished_name(writer.next(), issuer.distinguished_name);
674674
// Write validity
675675
writer.next().write_sequence(|writer| {
676676
// Not before
@@ -680,7 +680,7 @@ impl CertificateParams {
680680
Ok::<(), Error>(())
681681
})?;
682682
// Write subject
683-
write_distinguished_name(writer.next(), self.distinguished_name.clone());
683+
write_distinguished_name(writer.next(), &self.distinguished_name);
684684
// Write subjectPublicKeyInfo
685685
serialize_public_key_der(pub_key, writer.next());
686686
// write extensions
@@ -869,7 +869,7 @@ fn write_general_subtrees(writer: DERWriter, tag: u64, general_subtrees: &[Gener
869869
GeneralSubtree::Rfc822Name(name)
870870
| GeneralSubtree::DnsName(name) => writer.write_ia5_string(name),
871871
GeneralSubtree::DirectoryName(name) => {
872-
write_distinguished_name(writer, name.clone())
872+
write_distinguished_name(writer, name)
873873
},
874874
GeneralSubtree::IpAddress(subnet) => {
875875
writer.write_bytes(&subnet.to_bytes())

rcgen/src/crl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl CertificateRevocationListParams {
234234
// Write issuer.
235235
// RFC 5280 §5.1.2.3:
236236
// The issuer field MUST contain a non-empty X.500 distinguished name (DN).
237-
write_distinguished_name(writer.next(), issuer.distinguished_name.clone());
237+
write_distinguished_name(writer.next(), issuer.distinguished_name);
238238

239239
// Write thisUpdate date.
240240
// RFC 5280 §5.1.2.4:

rcgen/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ impl DistinguishedName {
338338
self.entries.push((ty, s.into()));
339339
}
340340

341-
/// Replaces the *fist occurrence* of a type with a new value.
341+
/// Replaces the *first occurrence* of a type with a new value.
342342
/// This is a convenience function to avoid duplicating values.
343343
///
344-
/// If there are multiple occurrences of a type there is currently no way of changing the besides iterating over the types and values of an existing instance and creating a new instance.
344+
/// If there are multiple occurrences of a type there is currently no way of changing them besides iterating over the types and values of an existing instance and creating a new instance.
345345
///
346346
/// ```
347347
/// # use rcgen::{DistinguishedName, DnType, DnValue};
@@ -586,7 +586,7 @@ fn write_dt_utc_or_generalized(writer: DERWriter, dt: OffsetDateTime) {
586586
}
587587
}
588588

589-
fn write_distinguished_name(writer: DERWriter, dn: DistinguishedName) {
589+
fn write_distinguished_name(writer: DERWriter, dn: &DistinguishedName) {
590590
writer.write_sequence(|writer| {
591591
for (ty, content) in dn.iter() {
592592
writer.next().write_set(|writer| {

rcgen/tests/openssl.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ use openssl::ssl::{HandshakeError, SslAcceptor, SslConnector, SslMethod};
77
use openssl::stack::Stack;
88
use openssl::x509::store::{X509Store, X509StoreBuilder};
99
use openssl::x509::{CrlStatus, X509Crl, X509Req, X509StoreContext, X509};
10+
use std::cell::RefCell;
11+
use std::io::{Error, ErrorKind, Read, Result as ioResult, Write};
12+
use std::rc::Rc;
13+
14+
#[cfg(feature = "x509-parser")]
15+
use {rcgen::Ia5String, std::str::FromStr};
16+
1017
use rcgen::{
1118
BasicConstraints, Certificate, CertificateParams, DnType, DnValue, GeneralSubtree, IsCa,
1219
KeyPair, NameConstraints,
1320
};
14-
use std::cell::RefCell;
15-
use std::io::{Error, ErrorKind, Read, Result as ioResult, Write};
16-
use std::rc::Rc;
1721

1822
mod util;
1923

@@ -542,9 +546,6 @@ fn test_openssl_pkcs1_and_sec1_keys() {
542546
#[test]
543547
#[cfg(feature = "x509-parser")]
544548
fn test_parse_certificate_with_multiple_domain_components() {
545-
use rcgen::Ia5String;
546-
use std::str::FromStr;
547-
548549
/// Command used to generate:
549550
/// `openssl req -x509 -newkey rsa:4096 -nodes -out mycert.pem -keyout mykey.pem -days 365 -subj "/C=US/ST=California/L=San Francisco/O=Example Company/OU=IT Department/CN=www.example.com/DC=example/DC=com"`
550551
/// Contains two distinct "DC" entries.

0 commit comments

Comments
 (0)