Skip to content

Commit 8e0466f

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

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
@@ -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: 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)