Canonical Encoding Rules

pyasn1.codec.cer.encoder.encode(value)

Turns ASN.1 object into CER octet stream.

Takes any ASN.1 object (e.g. PyAsn1Item derivative) walks all its components recursively and produces a CER octet stream.

Parameters:A pyasn1 object to encode
defMode: bool
If False, produces indefinite length encoding
maxChunkSize: int
Maximum chunk size in chunked encoding mode (0 denotes unlimited chunk size)
Returns:bytes (Python 3) or str (Python 2) – Given ASN.1 object encoded into BER octetstream
Raises:pyasn1.error.PyAsn1Error – On encoding errors
pyasn1.codec.cer.decoder.decode(substrate, asn1Spec=None)

Turns CER octet stream into an ASN.1 object.

Takes CER octetstream and decode it into an ASN.1 object (e.g. PyAsn1Item derivative) which may be a scalar or an arbitrary nested structure.

Parameters:
  • substrate (bytes (Python 3) or str (Python 2)) – CER octetstream
  • asn1Spec (any pyasn1 type object e.g. PyAsn1Item derivative) – A pyasn1 type object to act as a template guiding the decoder. Depending on the ASN.1 structure being decoded, asn1Spec may or may not be required. Most common reason for it to require is that ASN.1 structure is encoded in IMPLICIT tagging mode.
Returns:

tuple – A tuple of pyasn1 object recovered from CER substrate (PyAsn1Item derivative) and the unprocessed trailing portion of the substrate (may be empty)

Raises:

pyasn1.error.PyAsn1Error – On decoding errors