From 2920b4584cd768396b319a07d77820ef21220c6f Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 28 Apr 2023 22:34:09 +0200 Subject: [PATCH] Inline newtype macro for DistinguishedName --- rustls/src/msgs/handshake.rs | 52 +++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/rustls/src/msgs/handshake.rs b/rustls/src/msgs/handshake.rs index 5ea6e544..37d6e72f 100644 --- a/rustls/src/msgs/handshake.rs +++ b/rustls/src/msgs/handshake.rs @@ -1736,22 +1736,42 @@ impl TlsListElement for ClientCertificateType { const SIZE_LEN: ListLength = ListLength::U8; } -wrapped_payload!( - /// A `DistinguishedName` is a `Vec` wrapped in internal types. - /// - /// It contains the DER or BER encoded [`Subject` field from RFC 5280](https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.6) - /// for a single certificate. The Subject field is [encoded as an RFC 5280 `Name`](https://datatracker.ietf.org/doc/html/rfc5280#page-116). - /// It can be decoded using [x509-parser's FromDer trait](https://docs.rs/x509-parser/latest/x509_parser/prelude/trait.FromDer.html). - /// - /// ```ignore - /// for name in distinguished_names { - /// use x509_parser::prelude::FromDer; - /// println!("{}", x509_parser::x509::X509Name::from_der(&name.0)?.1); - /// } - /// ``` - DistinguishedName, - PayloadU16, -); +/// A `DistinguishedName` is a `Vec` wrapped in internal types. +/// +/// It contains the DER or BER encoded [`Subject` field from RFC 5280](https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.6) +/// for a single certificate. The Subject field is [encoded as an RFC 5280 `Name`](https://datatracker.ietf.org/doc/html/rfc5280#page-116). +/// It can be decoded using [x509-parser's FromDer trait](https://docs.rs/x509-parser/latest/x509_parser/prelude/trait.FromDer.html). +/// +/// ```ignore +/// for name in distinguished_names { +/// use x509_parser::prelude::FromDer; +/// println!("{}", x509_parser::x509::X509Name::from_der(&name.0)?.1); +/// } +/// ``` +#[derive(Clone, Debug)] +pub struct DistinguishedName(PayloadU16); + +impl From> for DistinguishedName { + fn from(v: Vec) -> Self { + Self(PayloadU16::new(v)) + } +} + +impl AsRef<[u8]> for DistinguishedName { + fn as_ref(&self) -> &[u8] { + self.0 .0.as_slice() + } +} + +impl Codec for DistinguishedName { + fn encode(&self, bytes: &mut Vec) { + self.0.encode(bytes); + } + + fn read(r: &mut Reader) -> Result { + Ok(Self(PayloadU16::read(r)?)) + } +} impl TlsListElement for DistinguishedName { const SIZE_LEN: ListLength = ListLength::U16;