1use der::asn1::ObjectIdentifier;
4use der::{ErrorKind, FixedTag, Tag};
5
6#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
8pub enum BagType {
9 Key,
11
12 Pkcs8,
14
15 Cert,
17
18 Crl,
20
21 Secret,
23
24 SafeContents,
26}
27
28impl FixedTag for BagType {
29 const TAG: Tag = Tag::ObjectIdentifier;
30}
31
32impl From<BagType> for ObjectIdentifier {
33 fn from(content_type: BagType) -> ObjectIdentifier {
34 match content_type {
35 BagType::Key => crate::PKCS_12_KEY_BAG_OID,
36 BagType::Pkcs8 => crate::PKCS_12_PKCS8_KEY_BAG_OID,
37 BagType::Cert => crate::PKCS_12_CERT_BAG_OID,
38 BagType::Crl => crate::PKCS_12_CRL_BAG_OID,
39 BagType::Secret => crate::PKCS_12_SECRET_BAG_OID,
40 BagType::SafeContents => crate::PKCS_12_SAFE_CONTENTS_BAG_OID,
41 }
42 }
43}
44
45impl TryFrom<ObjectIdentifier> for BagType {
46 type Error = der::Error;
47
48 fn try_from(oid: ObjectIdentifier) -> der::Result<Self> {
49 match oid {
50 crate::PKCS_12_KEY_BAG_OID => Ok(Self::Key),
51 crate::PKCS_12_PKCS8_KEY_BAG_OID => Ok(Self::Pkcs8),
52 crate::PKCS_12_CERT_BAG_OID => Ok(Self::Cert),
53 crate::PKCS_12_CRL_BAG_OID => Ok(Self::Crl),
54 crate::PKCS_12_SECRET_BAG_OID => Ok(Self::Secret),
55 crate::PKCS_12_SAFE_CONTENTS_BAG_OID => Ok(Self::SafeContents),
56 _ => Err(ErrorKind::OidUnknown { oid }.into()),
57 }
58 }
59}