Class DerSetOf
object --+
|
DerObject --+
|
DerSetOf
Class to model a DER SET OF.
An example of encoding is:
>>> from Crypto.Util.asn1 import DerBitString
>>> from binascii import hexlify, unhexlify
>>> so_der = DerSetOf([4,5])
>>> so_der.add(6)
>>> print hexlify(so_der.encode())
which will show 3109020104020105020106, the DER encoding
of a SET OF with items 4,5, and 6.
For decoding:
>>> s = unhexlify(b'3109020104020105020106')
>>> try:
>>> so_der = DerSetOf()
>>> so_der.decode(s)
>>> print [x for x in so_der]
>>> except (ValueError, EOFError):
>>> print "Not a valid DER SET OF"
the output will be [4L, 5L, 6L].
|
__init__(self,
startSet=None,
implicit=None)
Initialize the DER object as a SET OF. |
|
|
|
|
|
|
|
|
|
add(self,
elem)
Add an element to the set. |
|
|
|
decode(self,
derEle)
Decode a complete SET OF DER element, and re-initializes this
object with it. |
|
|
|
encode(self)
Return this SET OF DER element, fully encoded as a
binary string. |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
startSet=None,
implicit=None)
(Constructor)
|
|
Initialize the DER object as a SET OF.
- Parameters:
startSet (container) - The initial set of integers or DER encoded objects.
implicit (integer) - The IMPLICIT tag to use for the encoded object.
It overrides the universal tag for SET OF (17).
- Overrides:
object.__init__
|
Add an element to the set.
- Parameters:
elem (byte string or integer) - An element of the same type of objects already in the set.
It can be an integer or a DER encoded object.
|
Decode a complete SET OF DER element, and re-initializes this
object with it.
DER INTEGERs are decoded into Python integers. Any other DER
element is left undecoded; its validity is not checked.
- Parameters:
derEle (byte string) - A complete DER BIT SET OF.
- Raises:
ValueError - In case of parsing errors.
EOFError - If the DER element is too short.
- Overrides:
DerObject.decode
|
Return this SET OF DER element, fully encoded as a
binary string.
- Overrides:
DerObject.encode
|