Пример #1
0
def der_pack(value, hint='no_hint', der_packer=None, cls=None):
    """Pack a Python value into a binary string holding a DER blob; see
       der_format() for a version that does not include the DER header.
       Since native types may have been produced from a variety of
       ASN.1 types, the hint can be used to signal the type name
       (though any STRING trailer is stripped).  Alternatively,
       use cls to provide an ASN1Object subclass for packing or
       a der_packer instruction to apply.  The latter could crash
       if not properly formatted -- at least make sure its DER_ENTER_
       and DER_LEAVE nest properly and that the der_packer ends in
       DER_PACK_END.
    """
    if der_packer is not None:
        if not type(value) == list:
            value = [value]
        if cls is not None:
            raise Exception('der_pack(...,der_packer=...,cls=...) is ambiguous')
        if hint != 'no_hint':
            raise Exception('der_pack(...,der_packer=...,hint=...) is ambiguous')
        return _quickder.der_pack(der_packer, value)
    elif cls is not None:
        if not issubclass(cls, classes.ASN1Object):
            raise Exception('der_pack(value,cls=...) requires cls to be a subclass of ASN1Object')
        if not type(value) == list:
            value = [value]
        if hint != 'no_hint':
            raise Exception('der_pack(...,cls=...,hint=...) is ambiguous')
        return _quickder.der_pack(cls._der_packer, value)
    elif isinstance(value, classes.ASN1Object):
        return value._der_pack()
    else:
        (tag, packfun) = _der_hintmapping(type(value), hint)
        return primitive.der_prefixhead(tag, packfun(value))
Пример #2
0
 def _der_pack(self):
     """Return the result of the `der_pack()` operation on this
        element.
     """
     return primitive.der_prefixhead(self._der_packer[0],
                                     self._der_format())
Пример #3
0
 def _der_pack(self):
     """Return the result of the `der_pack()` operation on this
        element.
     """
     return primitive.der_prefixhead(self._der_packer[0], self._der_format())
Пример #4
0
 def _der_pack(self):
     """Return the result of the `der_pack()` operation on this
        element.
     """
     return primitive.der_prefixhead(DER_PACK_ENTER | DER_TAG_SET,
                                     self._der_format())
Пример #5
0
 def _der_pack(self):
     """Return the result of the `der_pack()` operation on this
        element.
     """
     return primitive.der_prefixhead(DER_PACK_ENTER | DER_TAG_SET,
                                     self._der_format())