Distinguished Encoding Rules


Turns ASN.1 object into DER octet stream.

Takes any ASN.1 object (e.g. PyAsn1Item derivative) walks all its components recursively and produces a DER 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:: :py:class:`pyasn1.error.PyAsn1Error` – On encoding errors
pyasn1.codec.der.decoder.decode(substrate, asn1Spec=None)

Turns DER octet stream into an ASN.1 object.

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

  • substrate (bytes (Python 3) or str (Python 2)) – DER 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.

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


: :py:class:`pyasn1.error.PyAsn1Error` – On decoding errors