• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# This file is part of pyasn1-modules software.
3#
4# Created by Russ Housley with assistance from asn1ate v.0.6.0.
5#
6# Copyright (c) 2019, Vigil Security, LLC
7# License: http://snmplabs.com/pyasn1/license.html
8#
9# CMS Algorithm Identifier Protection Attribute
10#
11# ASN.1 source from:
12# https://www.rfc-editor.org/rfc/rfc6211.txt
13#
14
15from pyasn1.type import constraint
16from pyasn1.type import namedtype
17from pyasn1.type import tag
18from pyasn1.type import univ
19
20from pyasn1_modules import rfc5652
21
22
23# Imports from RFC 5652
24
25DigestAlgorithmIdentifier = rfc5652.DigestAlgorithmIdentifier
26
27MessageAuthenticationCodeAlgorithm = rfc5652.MessageAuthenticationCodeAlgorithm
28
29SignatureAlgorithmIdentifier = rfc5652.SignatureAlgorithmIdentifier
30
31
32# CMS Algorithm Protection attribute
33
34id_aa_cmsAlgorithmProtect = univ.ObjectIdentifier('1.2.840.113549.1.9.52')
35
36
37class CMSAlgorithmProtection(univ.Sequence):
38    pass
39
40CMSAlgorithmProtection.componentType = namedtype.NamedTypes(
41    namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
42    namedtype.OptionalNamedType('signatureAlgorithm',
43        SignatureAlgorithmIdentifier().subtype(
44            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
45    namedtype.OptionalNamedType('macAlgorithm',
46        MessageAuthenticationCodeAlgorithm().subtype(
47            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
48)
49
50CMSAlgorithmProtection.subtypeSpec = constraint.ConstraintsUnion(
51    constraint.WithComponentsConstraint(
52        ('signatureAlgorithm', constraint.ComponentPresentConstraint()),
53        ('macAlgorithm', constraint.ComponentAbsentConstraint())),
54    constraint.WithComponentsConstraint(
55        ('signatureAlgorithm', constraint.ComponentAbsentConstraint()),
56        ('macAlgorithm', constraint.ComponentPresentConstraint()))
57)
58
59
60aa_cmsAlgorithmProtection = rfc5652.Attribute()
61aa_cmsAlgorithmProtection['attrType'] = id_aa_cmsAlgorithmProtect
62aa_cmsAlgorithmProtection['attrValues'][0] = CMSAlgorithmProtection()
63
64
65# Map of Attribute Type OIDs to Attributes are
66# added to the ones that are in rfc5652.py
67
68_cmsAttributesMapUpdate = {
69    id_aa_cmsAlgorithmProtect: CMSAlgorithmProtection(),
70}
71
72rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)