Package Crypto :: Package Util :: Module asn1 :: Class DerObjectId
[frames] | no frames]

Class DerObjectId

object --+    
         |    
 DerObject --+
             |
            DerObjectId

Class to model a DER OBJECT ID.

An example of encoding is:

>>> from Crypto.Util.asn1 import DerObjectId
>>> from binascii import hexlify, unhexlify
>>> oid_der = DerObjectId("1.2")
>>> oid_der.value += ".840.113549.1.1.1"
>>> print hexlify(oid_der.encode())

which will show 06092a864886f70d010101, the DER encoding for the RSA Object Identifier 1.2.840.113549.1.1.1.

For decoding:

>>> s = unhexlify(b'06092a864886f70d010101')
>>> try:
>>>   oid_der = DerObjectId()
>>>   oid_der.decode(s)
>>>   print oid_der.value
>>> except (ValueError, EOFError):
>>>   print "Not a valid DER OBJECT ID"

the output will be 1.2.840.113549.1.1.1.

Instance Methods
 
__init__(self, value='', implicit=None)
Initialize the DER object as an OBJECT ID.
 
encode(self)
Return the DER OBJECT ID, fully encoded as a binary string.
 
decode(self, derEle)
Decode a complete DER OBJECT ID, and re-initializes this object with it.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables
  value
The Object ID, a dot separated list of integers
Properties

Inherited from object: __class__

Method Details

__init__(self, value='', implicit=None)
(Constructor)

 
Initialize the DER object as an OBJECT ID.
Parameters:
  • value (string) - The initial Object Identifier (e.g. "1.2.0.0.6.2").
  • implicit (integer) - The IMPLICIT tag to use for the encoded object. It overrides the universal tag for OBJECT ID (6).
Overrides: object.__init__

encode(self)

 
Return the DER OBJECT ID, fully encoded as a binary string.
Overrides: DerObject.encode

decode(self, derEle)

 
Decode a complete DER OBJECT ID, and re-initializes this object with it.
Parameters:
  • derEle (byte string) - A complete DER OBJECT ID.
Raises:
  • ValueError - In case of parsing errors.
  • EOFError - If the DER element is too short.
Overrides: DerObject.decode