Skip to content

Commit dd62f8c

Browse files
committed
fixup! Allow multiple issuer items of the same kind
1 parent c33ce90 commit dd62f8c

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

rcgen/src/certificate.rs

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

617617
// According to the spec in RFC 2986, even if attributes are empty we need the empty attribute tag
@@ -673,7 +673,7 @@ impl CertificateParams {
673673
// Write signature algorithm
674674
issuer.key_pair.alg.write_alg_ident(writer.next());
675675
// Write issuer name
676-
write_distinguished_name(writer.next(), issuer.distinguished_name.clone());
676+
write_distinguished_name(writer.next(), issuer.distinguished_name);
677677
// Write validity
678678
writer.next().write_sequence(|writer| {
679679
// Not before
@@ -683,7 +683,7 @@ impl CertificateParams {
683683
Ok::<(), Error>(())
684684
})?;
685685
// Write subject
686-
write_distinguished_name(writer.next(), self.distinguished_name.clone());
686+
write_distinguished_name(writer.next(), &self.distinguished_name);
687687
// Write subjectPublicKeyInfo
688688
serialize_public_key_der(pub_key, writer.next());
689689
// write extensions
@@ -872,7 +872,7 @@ fn write_general_subtrees(writer: DERWriter, tag: u64, general_subtrees: &[Gener
872872
GeneralSubtree::Rfc822Name(name)
873873
| GeneralSubtree::DnsName(name) => writer.write_ia5_string(name),
874874
GeneralSubtree::DirectoryName(name) => {
875-
write_distinguished_name(writer, name.clone())
875+
write_distinguished_name(writer, name)
876876
},
877877
GeneralSubtree::IpAddress(subnet) => {
878878
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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#![cfg(feature = "pem")]
22

3+
use std::cell::RefCell;
4+
use std::io::{Error, ErrorKind, Read, Result as ioResult, Write};
5+
use std::rc::Rc;
6+
#[cfg(feature = "x509-parser")]
7+
use std::str::FromStr;
8+
39
use openssl::asn1::{Asn1Integer, Asn1Time};
410
use openssl::bn::BigNum;
511
use openssl::pkey::PKey;
612
use openssl::ssl::{HandshakeError, SslAcceptor, SslConnector, SslMethod};
713
use openssl::stack::Stack;
814
use openssl::x509::store::{X509Store, X509StoreBuilder};
915
use openssl::x509::{CrlStatus, X509Crl, X509Req, X509StoreContext, X509};
16+
17+
#[cfg(feature = "x509-parser")]
18+
use rcgen::Ia5String;
1019
use rcgen::{
1120
BasicConstraints, Certificate, CertificateParams, DnType, DnValue, GeneralSubtree, IsCa,
1221
KeyPair, NameConstraints,
1322
};
14-
use std::cell::RefCell;
15-
use std::io::{Error, ErrorKind, Read, Result as ioResult, Write};
16-
use std::rc::Rc;
1723

1824
mod util;
1925

@@ -542,9 +548,6 @@ fn test_openssl_pkcs1_and_sec1_keys() {
542548
#[test]
543549
#[cfg(feature = "x509-parser")]
544550
fn test_parse_certificate_with_multiple_domain_components() {
545-
use rcgen::Ia5String;
546-
use std::str::FromStr;
547-
548551
/// Command used to generate:
549552
/// `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"`
550553
/// Contains two distinct "DC" entries.

0 commit comments

Comments
 (0)