rasn_cms/
pkcs7_compat.rs

1//! PKCS7 compatibility module.
2//!
3//! The Cryptographic Message Syntax and PKCS7 are mostly the same. The only
4//! difference is that the `EncapsulatedContentInfo` content field has the `Any`
5//! type instead of the `OctetString`. See section 5.2.1. Compatibility with PKCS #7
6//! of RFC5652 for further information.
7use crate::{
8    Any, AuthAttributes, CertificateSet, CmsVersion, ContentType, Digest,
9    DigestAlgorithmIdentifier, DigestAlgorithmIdentifiers, MessageAuthenticationCode,
10    MessageAuthenticationCodeAlgorithm, OriginatorInfo, RecipientInfos, RevocationInfoChoices,
11    SignerInfos, UnauthAttributes,
12};
13use rasn::prelude::*;
14
15/// The content is represented in the type EncapsulatedContentInfo
16#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct EncapsulatedContentInfo {
18    pub content_type: ContentType,
19    #[rasn(tag(explicit(0)))]
20    pub content: Option<Any>,
21}
22
23/// SignedData represents a signed-data content type
24#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, Hash)]
25pub struct SignedData {
26    pub version: CmsVersion,
27    pub digest_algorithms: DigestAlgorithmIdentifiers,
28    pub encap_content_info: EncapsulatedContentInfo,
29    #[rasn(tag(0))]
30    pub certificates: Option<CertificateSet>,
31    #[rasn(tag(1))]
32    pub crls: Option<RevocationInfoChoices>,
33    pub signer_infos: SignerInfos,
34}
35
36/// DigestedData represents a digested-data content type
37#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
38pub struct DigestedData {
39    pub version: CmsVersion,
40    pub digest_algorithm: DigestAlgorithmIdentifier,
41    pub encap_content_info: EncapsulatedContentInfo,
42    pub digest: Digest,
43}
44
45/// AuthenticatedData represents an authenticated-data content type
46#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, Hash)]
47pub struct AuthenticatedData {
48    pub version: CmsVersion,
49    #[rasn(tag(0))]
50    pub originator_info: Option<OriginatorInfo>,
51    pub recipient_infos: RecipientInfos,
52    pub mac_algorithm: MessageAuthenticationCodeAlgorithm,
53    #[rasn(tag(1))]
54    pub digest_algorithm: Option<DigestAlgorithmIdentifier>,
55    pub encap_content_info: EncapsulatedContentInfo,
56    #[rasn(tag(2))]
57    pub auth_attrs: Option<AuthAttributes>,
58    pub mac: MessageAuthenticationCode,
59    #[rasn(tag(3))]
60    pub unauth_attrs: Option<UnauthAttributes>,
61}