codekingpro/portable-devtools
114k
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, LLC7# License: http://snmplabs.com/pyasn1/license.html8#9# CMS Algorithm Identifier Protection Attribute10#11# ASN.1 source from:12# https://www.rfc-editor.org/rfc/rfc6211.txt13#14 15from pyasn1.type import constraint16from pyasn1.type import namedtype17from pyasn1.type import tag18from pyasn1.type import univ19 20from pyasn1_modules import rfc565221 22 23# Imports from RFC 565224 25DigestAlgorithmIdentifier = rfc5652.DigestAlgorithmIdentifier26 27MessageAuthenticationCodeAlgorithm = rfc5652.MessageAuthenticationCodeAlgorithm28 29SignatureAlgorithmIdentifier = rfc5652.SignatureAlgorithmIdentifier30 31 32# CMS Algorithm Protection attribute33 34id_aa_cmsAlgorithmProtect = univ.ObjectIdentifier('1.2.840.113549.1.9.52')35 36 37class CMSAlgorithmProtection(univ.Sequence):38 pass39 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_cmsAlgorithmProtect62aa_cmsAlgorithmProtection['attrValues'][0] = CMSAlgorithmProtection()63 64 65# Map of Attribute Type OIDs to Attributes are66# added to the ones that are in rfc5652.py67 68_cmsAttributesMapUpdate = {69 id_aa_cmsAlgorithmProtect: CMSAlgorithmProtection(),70}71 72rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)