diff --git a/pkcs7/src/cms_version.rs b/pkcs7/src/cms_version.rs index 574f6e179..9655bd0a9 100644 --- a/pkcs7/src/cms_version.rs +++ b/pkcs7/src/cms_version.rs @@ -1,6 +1,7 @@ //! `CMSVersion` [RFC 5652 § 10.2.5](https://datatracker.ietf.org/doc/html/rfc5652#section-10.2.5) -use der::Enumerated; +use core::cmp::Ordering; +use der::{Enumerated, ValueOrd}; /// The CMSVersion type gives a syntax version number, for compatibility /// with future revisions of this specification. @@ -10,7 +11,7 @@ use der::Enumerated; /// ``` /// /// See [RFC 5652 10.2.5](https://datatracker.ietf.org/doc/html/rfc5652#section-10.2.5). -#[derive(Clone, Copy, Debug, Enumerated, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Enumerated, Eq, PartialEq, PartialOrd, Ord)] #[asn1(type = "INTEGER")] #[repr(u8)] pub enum CmsVersion { @@ -27,3 +28,16 @@ pub enum CmsVersion { /// syntax version 5 V5 = 5, } + +impl From for u8 { + fn from(version: CmsVersion) -> u8 { + version as u8 + } +} + +// TODO(tarcieri): fix `ValueOrd` derive for this case (`asn1` attribute is clashing) +impl ValueOrd for CmsVersion { + fn value_cmp(&self, other: &Self) -> der::Result { + Ok(self.cmp(other)) + } +} diff --git a/pkcs7/src/signer_info.rs b/pkcs7/src/signer_info.rs index 2c1dc1215..3bd2f83ad 100644 --- a/pkcs7/src/signer_info.rs +++ b/pkcs7/src/signer_info.rs @@ -1,7 +1,5 @@ //! `SignerInfo` data type [RFC 5652 § 5.3](https://datatracker.ietf.org/doc/html/rfc5652#section-5.3) -use core::cmp::Ordering; - use crate::cms_version::CmsVersion; use der::{ asn1::{OctetStringRef, SetOfVec}, @@ -37,7 +35,7 @@ type UnsignedAttributes<'a> = SetOfVec; // issuerAndSerialNumber IssuerAndSerialNumber, // subjectKeyIdentifier [0] SubjectKeyIdentifier } /// ``` -#[derive(Clone, Debug, PartialEq, Eq, Choice)] +#[derive(Clone, Debug, PartialEq, Eq, Choice, ValueOrd)] pub enum SignerIdentifier<'a> { /// issuer and serial number IssuerAndSerialNumber(IssuerAndSerialNumber), @@ -47,7 +45,7 @@ pub enum SignerIdentifier<'a> { SubjectKeyIdentifier(SubjectKeyIdentifier<'a>), } -#[derive(Clone, Debug, Eq, PartialEq, Sequence)] +#[derive(Clone, Debug, Eq, PartialEq, Sequence, ValueOrd)] #[allow(missing_docs)] pub struct IssuerAndSerialNumber { pub name: Name, @@ -71,7 +69,7 @@ pub type SignerInfos<'a> = SetOfVec>; /// signature SignatureValue, /// unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL } /// ``` -#[derive(Clone, Debug, Eq, PartialEq, Sequence)] +#[derive(Clone, Debug, Eq, PartialEq, Sequence, ValueOrd)] pub struct SignerInfo<'a> { /// the syntax version number. pub version: CmsVersion, @@ -96,10 +94,3 @@ pub struct SignerInfo<'a> { #[asn1(context_specific = "1", tag_mode = "IMPLICIT", optional = "true")] pub unsigned_attributes: Option>, } - -// TODO: figure out what ordering makes sense - if any -impl ValueOrd for SignerInfo<'_> { - fn value_cmp(&self, _other: &Self) -> der::Result { - Ok(Ordering::Equal) - } -}