Skip to content

Commit

Permalink
x509-cert: fixup string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Jun 27, 2023
1 parent 96186bb commit 31cd225
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion x509-cert/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl FromStr for RdnSequence {
/// [RFC 4514]: https://datatracker.ietf.org/doc/html/rfc4514
impl fmt::Display for RdnSequence {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for (i, atv) in self.0.iter().enumerate() {
// As per RFC 4514 Section 2.1, the elements are reversed
for (i, atv) in self.0.iter().rev().enumerate() {
match i {
0 => write!(f, "{}", atv)?,
_ => write!(f, ",{}", atv)?,
Expand Down
15 changes: 15 additions & 0 deletions x509-cert/tests/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ fn decode_name() {
counter += 1;
}
}

#[cfg(feature = "std")]
{
// https://datatracker.ietf.org/doc/html/rfc4514.html#section-2.1
// If the RDNSequence is an empty sequence, the result is the empty or
// zero-length string.
// Otherwise, the output consists of the string encodings of each
// RelativeDistinguishedName in the RDNSequence (according to Section 2.2),
// starting with the last element of the sequence and moving backwards
// toward the first.
// The encodings of adjoining RelativeDistinguishedNames are separated by
// a comma (',' U+002C) character.
let name = rdn1a.to_string();
assert_eq!(name, "CN=Good CA,O=Test Certificates 2011,C=US");
}
}

#[test]
Expand Down

0 comments on commit 31cd225

Please sign in to comment.