Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
rfc8696.py105 linesDownload Raw Back to pyasn1_modules
1#2# This file is part of pyasn1-modules software.3#4# Created by Russ Housley with some assistance from asn1ate v.0.6.0.5#6# Copyright (c) 2019, Vigil Security, LLC7# License: http://snmplabs.com/pyasn1/license.html8#9# Using Pre-Shared Key (PSK) in the Cryptographic Message Syntax (CMS)10#11# ASN.1 source from:12# https://www.rfc-editor.org/rfc/rfc8696.txt13#14 15from pyasn1.type import constraint16from pyasn1.type import namedtype17from pyasn1.type import namedval18from pyasn1.type import tag19from pyasn1.type import univ20 21from pyasn1_modules import rfc565222 23MAX = float('inf')24 25 26id_ori = univ.ObjectIdentifier('1.2.840.113549.1.9.16.13')27 28id_ori_keyTransPSK = univ.ObjectIdentifier('1.2.840.113549.1.9.16.13.1')29 30id_ori_keyAgreePSK = univ.ObjectIdentifier('1.2.840.113549.1.9.16.13.2')31 32 33class PreSharedKeyIdentifier(univ.OctetString):34    pass35 36 37class KeyTransRecipientInfos(univ.SequenceOf):38    componentType = rfc5652.KeyTransRecipientInfo()39 40 41class KeyTransPSKRecipientInfo(univ.Sequence):42    componentType = namedtype.NamedTypes(43        namedtype.NamedType('version',44            rfc5652.CMSVersion()),45        namedtype.NamedType('pskid',46            PreSharedKeyIdentifier()),47        namedtype.NamedType('kdfAlgorithm',48            rfc5652.KeyDerivationAlgorithmIdentifier()),49        namedtype.NamedType('keyEncryptionAlgorithm',50            rfc5652.KeyEncryptionAlgorithmIdentifier()),51        namedtype.NamedType('ktris',52            KeyTransRecipientInfos()),53        namedtype.NamedType('encryptedKey',54            rfc5652.EncryptedKey())55    )56 57 58class KeyAgreePSKRecipientInfo(univ.Sequence):59    componentType = namedtype.NamedTypes(60        namedtype.NamedType('version',61            rfc5652.CMSVersion()),62        namedtype.NamedType('pskid',63            PreSharedKeyIdentifier()),64        namedtype.NamedType('originator',65            rfc5652.OriginatorIdentifierOrKey().subtype(explicitTag=tag.Tag(66                tag.tagClassContext, tag.tagFormatConstructed, 0))),67        namedtype.OptionalNamedType('ukm',68            rfc5652.UserKeyingMaterial().subtype(explicitTag=tag.Tag(69                tag.tagClassContext, tag.tagFormatSimple, 1))),70        namedtype.NamedType('kdfAlgorithm',71            rfc5652.KeyDerivationAlgorithmIdentifier()),72        namedtype.NamedType('keyEncryptionAlgorithm',73            rfc5652.KeyEncryptionAlgorithmIdentifier()),74        namedtype.NamedType('recipientEncryptedKeys',75            rfc5652.RecipientEncryptedKeys())76    )77 78 79class CMSORIforPSKOtherInfo(univ.Sequence):80    componentType = namedtype.NamedTypes(81        namedtype.NamedType('psk',82            univ.OctetString()),83        namedtype.NamedType('keyMgmtAlgType',84            univ.Enumerated(namedValues=namedval.NamedValues(85                ('keyTrans', 5), ('keyAgree', 10)))),86        namedtype.NamedType('keyEncryptionAlgorithm',87            rfc5652.KeyEncryptionAlgorithmIdentifier()),88        namedtype.NamedType('pskLength',89            univ.Integer().subtype(90                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),91        namedtype.NamedType('kdkLength',92            univ.Integer().subtype(93                subtypeSpec=constraint.ValueRangeConstraint(1, MAX)))94    )95 96 97# Update the CMS Other Recipient Info map in rfc5652.py98 99_otherRecipientInfoMapUpdate = {100    id_ori_keyTransPSK: KeyTransPSKRecipientInfo(),101    id_ori_keyAgreePSK: KeyAgreePSKRecipientInfo(),102}103 104rfc5652.otherRecipientInfoMap.update(_otherRecipientInfoMapUpdate)105 
codekingpro/portable-devtools · Team Ai