cms/
revocation.rs

1//! Revocation-related types
2use core::cmp::Ordering;
3
4use der::asn1::SetOfVec;
5use der::{Any, Choice, Sequence, ValueOrd};
6use spki::AlgorithmIdentifierOwned;
7
8use x509_cert::crl::CertificateList;
9use x509_cert::impl_newtype;
10
11/// The `RevocationInfoChoices` type is defined in [RFC 5652 Section 10.2.1].
12///
13/// ```text
14///   RevocationInfoChoices ::= SET OF RevocationInfoChoice
15/// ```
16///
17/// [RFC 5652 Section 10.2.1]: https://www.rfc-editor.org/rfc/rfc5652#section-10.2.1
18#[derive(Clone, Eq, PartialEq, Debug)]
19pub struct RevocationInfoChoices(pub SetOfVec<RevocationInfoChoice>);
20impl_newtype!(RevocationInfoChoices, SetOfVec<RevocationInfoChoice>);
21
22/// The `RevocationInfoChoice` type is defined in [RFC 5652 Section 10.2.1].
23///
24/// ```text
25///   RevocationInfoChoice ::= CHOICE {
26///       crl CertificateList,
27///       ...,
28///       [[5: other [1] IMPLICIT OtherRevocationInfoFormat ]] }
29/// ```
30///
31/// [RFC 5652 Section 10.2.1]: https://www.rfc-editor.org/rfc/rfc5652#section-10.2.1
32#[derive(Clone, Debug, Eq, PartialEq, Choice)]
33#[allow(missing_docs)]
34#[allow(clippy::large_enum_variant)]
35pub enum RevocationInfoChoice {
36    Crl(CertificateList),
37    #[asn1(context_specific = "1", tag_mode = "IMPLICIT", constructed = "true")]
38    Other(OtherRevocationInfoFormat),
39}
40
41// TODO DEFER ValueOrd is not supported for CHOICE types (see new_enum in value_ord.rs)
42impl ValueOrd for RevocationInfoChoice {
43    fn value_cmp(&self, other: &Self) -> der::Result<Ordering> {
44        use der::DerOrd;
45        use der::Encode;
46        self.to_der()?.der_cmp(&other.to_der()?)
47    }
48}
49
50#[cfg(feature = "std")]
51impl TryFrom<std::vec::Vec<RevocationInfoChoice>> for RevocationInfoChoices {
52    type Error = der::Error;
53
54    fn try_from(vec: std::vec::Vec<RevocationInfoChoice>) -> der::Result<RevocationInfoChoices> {
55        Ok(RevocationInfoChoices(SetOfVec::try_from(vec)?))
56    }
57}
58
59/// The `RevocationInfoChoices` type is defined in [RFC 5652 Section 10.2.1].
60///
61/// ```text
62///   OtherRevocationInfoFormat ::= SEQUENCE {
63///       otherRevInfoFormat    OTHER-REVOK-INFO.
64///               &id({SupportedOtherRevokInfo}),
65///       otherRevInfo          OTHER-REVOK-INFO.
66///               &Type({SupportedOtherRevokInfo}{@otherRevInfoFormat})}
67/// ```
68///
69/// [RFC 5652 Section 10.2.1]: https://www.rfc-editor.org/rfc/rfc5652#section-10.2.1
70#[derive(Clone, Debug, Eq, PartialEq, Sequence)]
71#[allow(missing_docs)]
72pub struct OtherRevocationInfoFormat {
73    pub other_format: AlgorithmIdentifierOwned,
74    pub other: Any,
75}