The code below to illustrates the problem. The code produces two different hex strings:
I believe that the first one is correct! The empty SEQUENCE should not be omitted in this situation.
#!/usr/bin/env python
from pyasn1.codec.der.decoder import decode as der_decode
from pyasn1.codec.der.encoder import encode as der_encode
from pyasn1.type import univ, namedtype
from pyasn1_modules import rfc5280
import binascii
oid = univ.ObjectIdentifier((1, 2, 410, 200046, 1, 2))
class PadAlgo(univ.Choice):
componentType = namedtype.NamedTypes(
namedtype.NamedType('specifiedPadAlgo', univ.OctetString()),
namedtype.NamedType('generalPadAlgo', univ.ObjectIdentifier())
)
pad_algo_1 = PadAlgo()
pad_algo_1['specifiedPadAlgo'] = univ.OctetString(hexValue='01')
class CbcParameters(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('m', univ.Integer().subtype(value=1)),
namedtype.DefaultedNamedType('padAlgo', pad_algo_1)
)
algorithmIdentifierMapUpdate = {
oid: CbcParameters(),
}
rfc5280.algorithmIdentifierMap.update(algorithmIdentifierMapUpdate)
param = CbcParameters()
param['m'] = 1
param['padAlgo'] = pad_algo_1
AlgoId = rfc5280.AlgorithmIdentifier()
AlgoId['algorithm'] = oid
AlgoId['parameters'] = der_encode(param)
substrate = der_encode(AlgoId)
print(binascii.hexlify(substrate))
asn1Object, rest = der_decode(substrate,
asn1Spec=rfc5280.AlgorithmIdentifier(),
decodeOpenTypes=True)
substrate = der_encode(asn1Object)
print(binascii.hexlify(substrate))
The code below to illustrates the problem. The code produces two different hex strings:
300c06082a831a8c9a6e01023000
300a06082a831a8c9a6e0102
I believe that the first one is correct! The empty SEQUENCE should not be omitted in this situation.