Package Crypto :: Package Util :: Module asn1 :: Class DerObject
[hide private]
[frames] | no frames]

Class DerObject

Known Subclasses:

Base class for defining a single DER object.

Instantiate this class ONLY when you have to decode a DER element.

Instance Methods [hide private]
 
__init__(self, ASN1Type=None, payload='')
Initialize the DER object according to a specific type.
 
isType(self, ASN1Type)
 
_lengthOctets(self, payloadLen)
Return a byte string that encodes the given payload length (in bytes) in a format suitable for a DER length tag (L).
 
encode(self)
Return a complete DER element, fully encoded as a TLV.
 
_decodeLen(self, idx, der)
Given a (part of a) DER element, and an index to the first byte of a DER length tag (L), return a tuple with the payload size, and the index of the first byte of the such payload (V).
 
decode(self, derEle, noLeftOvers=0)
Decode a complete DER element, and re-initializes this object with it.
Class Variables [hide private]
  typeTags = {'BIT STRING': 3, 'INTEGER': 2, 'NULL': 5, 'OBJECT ...
Method Details [hide private]

__init__(self, ASN1Type=None, payload='')
(Constructor)

 

Initialize the DER object according to a specific type.

The ASN.1 type is either specified as the ASN.1 string (e.g. 'SEQUENCE'), directly with its numerical tag or with no tag at all (None).

_decodeLen(self, idx, der)

 

Given a (part of a) DER element, and an index to the first byte of a DER length tag (L), return a tuple with the payload size, and the index of the first byte of the such payload (V).

Raises a ValueError exception if the DER length is invalid. Raises an IndexError exception if the DER element is too short.

decode(self, derEle, noLeftOvers=0)

 

Decode a complete DER element, and re-initializes this object with it.

@param derEle A complete DER element. It must start with a DER T
tag.
@param noLeftOvers Indicate whether it is acceptable to complete the
parsing of the DER element and find that not all bytes in derEle have been used.

@return Index of the first unused byte in the given DER element.

Raises a ValueError exception in case of parsing errors. Raises an IndexError exception if the DER element is too short.


Class Variable Details [hide private]

typeTags

Value:
{'BIT STRING': 3,
 'INTEGER': 2,
 'NULL': 5,
 'OBJECT IDENTIFIER': 6,
 'OCTET STRING': 4,
 'SEQUENCE': 48}