net/data/ssl/scripts/asn1.py
def ToDER(obj):
  '''ToDER converts the given object into DER encoding'''
  if obj is None:
    # None turns into NULL
    return TagAndLength(5, 0)
  if isinstance(obj, (str, bytes)):
    # There are many ASN.1 string types, so rather than pick one implicitly,
    # require the caller explicitly specify the encoding with asn1.UTF8String,
    # etc., below.
    raise TypeError("String types must be specified explicitly")
  if isinstance(obj, bool):
    val = b"\x00"
    if obj:
      val = b"\xff"
    return TagAndData(1, val)
  if isinstance(obj, int):
    big_endian = bytearray()
    val = obj
    while val != 0:
      big_endian.append(val & 0xff)
      val >>= 8

    if len(big_endian) == 0 or big_endian[-1] >= 128:
      big_endian.append(0)

    big_endian.reverse()
    return TagAndData(2, bytes(big_endian))

  return obj.ToDER()
ToDER converts the given object into DER encoding
ToDER converts the given object into DER encoding
ToDER converts the given object into DER encoding
def ToDER(obj):
  if obj is None:
    return TagAndLength(5, 0)
  if isinstance(obj, (str, bytes)):
    raise TypeError("String types must be specified explicitly")
  if isinstance(obj, bool):
    val = b"\x00"
    if obj:
      val = b"\xff"
    return TagAndData(1, val)
  if isinstance(obj, int):
    big_endian = bytearray()
    val = obj
    while val != 0:
      big_endian.append(val & 0xff)
      val >>= 8
    if len(big_endian) == 0 or big_endian[-1] >= 128:
      big_endian.append(0)
    big_endian.reverse()
    return TagAndData(2, bytes(big_endian))
  return obj.ToDER()
def ToDER ( obj ) : if obj is None : return TagAndLength ( 5 , 0 ) if isinstance ( obj , ( str , bytes ) ) : raise TypeError ( "String types must be specified explicitly" ) if isinstance ( obj , bool ) : val = b"\x00" if obj : val = b"\xff" return TagAndData ( 1 , val ) if isinstance ( obj , int ) : big_endian = bytearray ( ) val = obj while val != 0 : big_endian . append ( val & 0xff ) val >>= 8 if len ( big_endian ) == 0 or big_endian [ - 1 ] >= 128 : big_endian . append ( 0 ) big_endian . reverse ( ) return TagAndData ( 2 , bytes ( big_endian ) ) return obj . ToDER ( )
ToDER converts the given object into DER encoding
ToDER converts the given object into DER encoding
'''ToDER converts the given object into DER encoding''' # None turns into NULL # There are many ASN.1 string types, so rather than pick one implicitly, # require the caller explicitly specify the encoding with asn1.UTF8String, # etc., below.
obj