+
    '(jI                         ^ RI t ^ RIHtHtHt ^ RIHtHt . ROtRR lt	 ! R R]
4      t ! R R]
4      t ! R R]4      t ! R R]4      t ! R R	]4      t ! R R]4      t ! R R]4      t ! R R
]4      t ! R R]4      t ! R R]4      tR# )    N)byte_stringbchrbord)long_to_bytesbytes_to_long	DerObject
DerInteger
DerBooleanDerOctetStringDerNullDerSequenceDerObjectIdDerBitStringDerSetOfc                 d    ^ p W,           pT'       * ;'       g    T ^ 8  #   \          d     R# i ; i)r   F)	TypeError)xonly_non_negativetests   && E/home/ubuntu/cf-venv/lib/python3.14/site-packages/Crypto/Util/asn1.py
_is_numberr   (   s>    Dx ! **AF*  s     //c                   H   a  ] tR t^1t o RtR tR tR tR tR t	R t
RtV tR	# )
BytesIO_EOFzaThis class differs from BytesIO in that a ValueError exception is
raised whenever EOF is reached.c                .    Wn         ^ V n        RV n        R# )r   N)_buffer_index	_bookmark)selfinitial_bytess   &&r   __init__BytesIO_EOF.__init__5   s    $    c                (    V P                   V n        R # N)r   r   r   s   &r   set_bookmarkBytesIO_EOF.set_bookmark:   s    r"   c                h    V P                   f   Q hV P                  V P                   V P                   # r$   r   r   r   r%   s   &r   data_since_bookmarkBytesIO_EOF.data_since_bookmark=   s+    ~~)))||DNN4;;77r"   c                N    \        V P                  4      V P                  ,
          # r$   )lenr   r   r%   s   &r   remaining_dataBytesIO_EOF.remaining_dataA   s    4<< 4;;..r"   c                    V P                   V,           pV\        V P                  4      8  d(   \        R V\        V P                  4      3,          4      hV P                  V P                   V pW n         V# )z@Not enough data for DER decoding: expected %d bytes and found %d)r   r-   r   
ValueError)r   length	new_indexresults   &&  r   readBytesIO_EOF.readD   sp    KK&(	s4<<((_clnqrvr~r~n  cA  A  B  Bdkk)4r"   c                D    \        V P                  ^4      ^ ,          4      # )   )r   r5   r%   s   &r   	read_byteBytesIO_EOF.read_byteM   s    DIIaLO$$r"   r)   N)__name__
__module____qualname____firstlineno____doc__r    r&   r*   r.   r5   r9   __static_attributes____classdictcell____classdict__s   @r   r   r   1   s-     '
%8/% %r"   r   c                   `   a  ] tR t^Qt o RtRR ltR t]R 4       tR t	R t
RR ltR	 tR
tV tR# )r   z`Base class for defining a single DER object.

This class should never be directly instantiated.
Nc                Z   Vf
   RV n         R# V P                  V4      pW n        V'       d   ^ M^ pRWS39  d   \        R4      hVe'   ^V,          V P                  V4      ,          V n         R# Ve-   ^V P                  V4      ,          V n         Wa,          V n        R# Wa,          V n         R# )a  Initialize the DER object according to a specific ASN.1 type.

:Parameters:
  asn1Id : integer or byte
    The universal DER tag number for this object
    (e.g. 0x10 for a SEQUENCE).
    If None, the tag is not known yet.

  payload : byte string
    The initial payload of the object (that it,
    the content octets).
    If not specified, the payload is empty.

  implicit : integer or byte
    The IMPLICIT tag number (< 0x1F) to use for the encoded object.
    It overrides the universal tag *asn1Id*.
    It cannot be combined with the ``explicit`` parameter.
    By default, there is no IMPLICIT tag.

  constructed : bool
    True when the ASN.1 type is *constructed*.
    False when it is *primitive* (default).

  explicit : integer or byte
    The EXPLICIT tag number (< 0x1F) to use for the encoded object.
    It cannot be combined with the ``implicit`` parameter.
    By default, there is no EXPLICIT tag.
Nz1Explicit and implicit tags are mutually exclusive)
_tag_octet_convertTagpayloadr1   _inner_tag_octet)r   asn1IdrH   implicitconstructedexplicitconstructed_bits   &&&&&& r   r    DerObject.__init__W   s    > >&*DO))&1&  +6$433$ &; < < '&*_&<t?O?OPX?Y&YDO)&1D4D4DX4N&NDO,;,DD) '6&>DOr"   c                    \        V4      '       g#   \        V4      ^8X  d   \        V^ ,          4      p\        V4      '       d   ^ Tu;8:  d   ^8  g   M \        R4      hV# )z_Check if *tag* is a real DER tag (5 bits).
Convert it from a character to number if necessary.
zWrong DER tag)r   r-   r   r1   )r   tags   &&r   rG   DerObject._convertTag   sH     "#3x1}"3q6l"3AOtO$_55
r"   c                    V ^8  d.   \        V 4      p\        \        V4      ^,           4      V,           # \        V 4      # )z8Build length octets according to BER/DER
definite form.
)r   r   r-   )r2   encodings   & r   _definite_formDerObject._definite_form   s8    
 C<#0#8#CMC$788CCF|#r"   c                R   V P                   p\        V R4      '       dP   \        V P                  4      V P	                  \        V P                   4      4      ,           V P                   ,           p\        V P                  4      V P	                  \        V4      4      ,           V,           # )z?Return this DER element, fully encoded as a binary byte string.rI   )rH   hasattrr   rI   rU   r-   rF   )r   output_payloads   & r   encodeDerObject.encode   s     "& 4!344&*4+@+@&A&*&9&9#dll:K&L'M&*ll'3N T__-++C,?@A&' (r"   c                    VP                  4       pV^8  dX   VP                  V^,          4      p\        V^ ,          4      ^ 8X  d   \        R4      h\	        V4      pV^8:  d   \        R4      hV# )z%Decode DER length octets from a file.z$Invalid DER: length has leading zeroz5Invalid DER: length in long form but smaller than 128)r9   r5   r   r1   r   )r   sr2   encoded_lengths   &&  r   
_decodeLenDerObject._decodeLen   sh     C<%&VVFTM%:NN1-.!3()OPP*>:F}()`aar"   c                    \        V4      '       g   \        R4      h\        V4      pV P                  W24       VP	                  4       ^ 8  d   \        R4      hV # )zDecode a complete DER element, and re-initializes this
object with it.

Args:
  der_encoded (byte string): A complete DER element.

Raises:
  ValueError: in case of parsing errors.
zInput is not a byte string-Unexpected extra data after the DER structure)r   r1   r   _decodeFromStreamr.   )r   der_encodedstrictr]   s   &&& r   decodeDerObject.decode   sW     #;//$%ABB,&&q1 ##%)$%TUUr"   c                
   VP                  4       pV P                  e   W0P                  8w  d   \        R4      hMW0n        V P                  V4      pVP	                  V4      V n        \        V R4      '       d   \        V P
                  4      pVP                  4       pW`P                  8w  d   \        R4      hV P                  V4      pVP	                  V4      V n        VP                  4       ^ 8  d   \        R4      hR# R# )z*Decode a complete DER element from a file.NzUnexpected DER tagrI   zUnexpected internal DER tagrb   )
r9   rF   r1   r_   r5   rH   rX   r   rI   r.   )r   r]   re   idOctetr2   pinner_octets   &&&    r   rc   DerObject._decodeFromStream   s     ++-??.//1()=>> 2 '.O+ vvf~ 4!344#DLL1A"#++-K"&;&;;()FGG!__Q/F#$66&>DL '')A-()XYY . 5r"   )rI   rF   rH   )Nr"   NFNF)r;   r<   r=   r>   r?   r    rG   staticmethodrU   rZ   r_   rf   rc   r@   rA   rB   s   @r   r   r   Q   sE     	
D	?L
	 
	$ 
	$	(&		.	Z 	Zr"   c                   D   a  ] tR tRt o RtR	R ltR tR
R ltR tRt	V t
R# )r	   i  a8  Class to model a DER INTEGER.

An example of encoding is::

  >>> from Crypto.Util.asn1 import DerInteger
  >>> from binascii import hexlify, unhexlify
  >>> int_der = DerInteger(9)
  >>> print hexlify(int_der.encode())

which will show ``020109``, the DER encoding of 9.

And for decoding::

  >>> s = unhexlify(b'020109')
  >>> try:
  >>>   int_der = DerInteger()
  >>>   int_der.decode(s)
  >>>   print int_der.value
  >>> except ValueError:
  >>>   print "Not a valid DER INTEGER"

the output will be ``9``.

:ivar value: The integer value
:vartype value: integer
Nc                F    \         P                  V ^RVRV4       Wn        R# )zInitialize the DER object as an INTEGER.

:Parameters:
  value : integer
    The value of the integer.

  implicit : integer
    The IMPLICIT tag to use for the encoded object.
    It overrides the universal tag for INTEGER (2).
r"   FNr   r    valuer   rr   rK   rM   s   &&&&r   r    DerInteger.__init__#  s$     ""4sH#((4"
r"   c                X   V P                   pRV n         \        \        V^,          4      4      V P                  ,           V n        ^Tu;8:  d   ^8:  d%   M M!\        ^ 4      V P                  ,           V n        RTu;8:  d   ^8:  d   M MMV^,          pK  \        P                  V 4      # )z9Return the DER INTEGER, fully encoded as a
binary string.r"   i)rr   rH   r   intr   rZ   )r   numbers   & r   rZ   DerInteger.encode3  s     "#'FSL(9#:T\\#IDLf++'+DzDLL'@v,,qLF ''--r"   c                0    \         P                  WVR7      # )zDecode a DER-encoded INTEGER, and re-initializes this
object with it.

Args:
  der_encoded (byte string): A complete INTEGER DER element.

Raises:
  ValueError: in case of parsing errors.
re   r   rf   r   rd   re   s   &&&r   rf   DerInteger.decodeB  s     !''&'IIr"   c                   \         P                  WV4       V'       d   \        V P                  4      ^ 8X  d   \	        R4      h\        V P                  4      ^8  d@   \
        P                  ! RV P                  R,          4      ^ ,          ^8  d   \	        R4      h^ V n        ^pV P                   FG  pV ;P                  R,          un        V ;P                  \        V4      ,          un        V^,          pKI  	  V P                  '       dG   \        V P                  ^ ,          4      ^,          '       d   V ;P                  V,          un        R# R# R# )z*Decode a complete DER INTEGER from a file.z/Invalid encoding for DER INTEGER: empty payloadz>H:N   Nz.Invalid encoding for DER INTEGER: leading zero   N)	r   rc   r-   rH   r1   structunpackrr   r   )r   r]   re   bitsis   &&&  r   rc   DerInteger._decodeFromStreamO  s     ++DV<4<<(A-()Z[[4<<(A-&--dllSUFV2WXY2Z]a2a()YZZ 
AJJ#%JJJ$q')JQJD & <<<Da$9D$@$@JJ$&J %A<r"   rH   rr   )r   NNrm   r;   r<   r=   r>   r?   r    rZ   rf   rc   r@   rA   rB   s   @r   r	   r	     s$     	6	# 	.	J	' 	'r"   c                   D   a  ] tR tRt o RtR	R ltR tR
R ltR tRt	V t
R# )r
   if  a  Class to model a DER-encoded BOOLEAN.

An example of encoding is::

>>> from Crypto.Util.asn1 import DerBoolean
>>> bool_der = DerBoolean(True)
>>> print(bool_der.encode().hex())

which will show ``0101ff``, the DER encoding of True.

And for decoding::

>>> s = bytes.fromhex('0101ff')
>>> try:
>>>   bool_der = DerBoolean()
>>>   bool_der.decode(s)
>>>   print(bool_der.value)
>>> except ValueError:
>>>   print "Not a valid DER BOOLEAN"

the output will be ``True``.

:ivar value: The boolean value
:vartype value: boolean
Nc                F    \         P                  V ^RVRV4       Wn        R# )a6  Initialize the DER object as a BOOLEAN.

Args:
  value (boolean):
    The value of the boolean. Default is False.

  implicit (integer or byte):
    The IMPLICIT tag number (< 0x1F) to use for the encoded object.
    It overrides the universal tag for BOOLEAN (1).
    It cannot be combined with the ``explicit`` parameter.
    By default, there is no IMPLICIT tag.

  explicit (integer or byte):
    The EXPLICIT tag number (< 0x1F) to use for the encoded object.
    It cannot be combined with the ``implicit`` parameter.
    By default, there is no EXPLICIT tag.
r"   FNrq   rs   s   &&&&r   r    DerBoolean.__init__  s!    & 	4sHeXF
r"   c                b    V P                   '       d   RMRV n        \        P                  V 4      # )z9Return the DER BOOLEAN, fully encoded as a binary string.       rr   rH   r   rZ   r%   s   &r   rZ   DerBoolean.encode  s&     #'***w'%%r"   c                .    \         P                  WV4      # )zDecode a DER-encoded BOOLEAN, and re-initializes this object with it.

Args:
    der_encoded (byte string): A DER-encoded BOOLEAN.

Raises:
    ValueError: in case of parsing errors.
r{   r|   s   &&&r   rf   DerBoolean.decode  s     6::r"   c                6   \         P                  WV4       \        V P                  4      ^8w  d   \	        R4      h\        V P                  ^ ,          4      ^ 8X  d
   RV n        R# \        V P                  ^ ,          4      ^8X  d
   RV n        R# \	        R4      h)z)Decode a DER-encoded BOOLEAN from a file.z7Invalid encoding for DER BOOLEAN: payload is not 1 byteFTzInvalid payload for DER BOOLEANN)r   rc   r-   rH   r1   r   rr   r   r]   re   s   &&&r   rc   DerBoolean._decodeFromStream  su     	##DV4t||!VWWQ A%DJ$,,q/"d*DJ>??r"   r   )FNNrm   r   rB   s   @r   r
   r
   f  s%     2,&
;@ @r"   c                      a  ] tR tRt o RtRR ltR tR tR tR t	R	 t
R
 tR tR tR tR tRR ltRR ltR tRR ltR tRtV tR# )r   i  a  Class to model a DER SEQUENCE.

This object behaves like a dynamic Python sequence.

Sub-elements that are INTEGERs behave like Python integers.

Any other sub-element is a binary string encoded as a complete DER
sub-element (TLV).

An example of encoding is:

  >>> from Crypto.Util.asn1 import DerSequence, DerInteger
  >>> from binascii import hexlify, unhexlify
  >>> obj_der = unhexlify('070102')
  >>> seq_der = DerSequence([4])
  >>> seq_der.append(9)
  >>> seq_der.append(obj_der.encode())
  >>> print hexlify(seq_der.encode())

which will show ``3009020104020109070102``, the DER encoding of the
sequence containing ``4``, ``9``, and the object with payload ``02``.

For decoding:

  >>> s = unhexlify(b'3009020104020109070102')
  >>> try:
  >>>   seq_der = DerSequence()
  >>>   seq_der.decode(s)
  >>>   print len(seq_der)
  >>>   print seq_der[0]
  >>>   print seq_der[:]
  >>> except ValueError:
  >>>   print "Not a valid DER SEQUENCE"

the output will be::

  3
  4
  [4, 9, b'']

Nc                `    \         P                  V ^RVRV4       Vf
   . V n        R# Wn        R# )ac  Initialize the DER object as a SEQUENCE.

:Parameters:
  startSeq : Python sequence
    A sequence whose element are either integers or
    other DER objects.

  implicit : integer or byte
    The IMPLICIT tag number (< 0x1F) to use for the encoded object.
    It overrides the universal tag for SEQUENCE (16).
    It cannot be combined with the ``explicit`` parameter.
    By default, there is no IMPLICIT tag.

  explicit : integer or byte
    The EXPLICIT tag number (< 0x1F) to use for the encoded object.
    It cannot be combined with the ``implicit`` parameter.
    By default, there is no EXPLICIT tag.
r"   TN)r   r    _seq)r   startSeqrK   rM   s   &&&&r   r    DerSequence.__init__  s.    ( ""4sHdHM# "DI (Ir"   c                     V P                   V R # r$   r   r   ns   &&r   __delitem__DerSequence.__delitem__   s    IIaLr"   c                (    V P                   V,          # r$   r   r   s   &&r   __getitem__DerSequence.__getitem__  s    yy|#r"   c                "    W P                   V&   R # r$   r   )r   keyrr   s   &&&r   __setitem__DerSequence.__setitem__  s    !&		#r"   c                     W0P                   W% R # r$   r   )r   r   jsequences   &&&&r   __setslice__DerSequence.__setslice__	  s    !)		!r"   c                "    V P                   W1 R # r$   r   r   r   r   s   &&&r   __delslice__DerSequence.__delslice__  s    IIacNr"   c                H    V P                   \        ^ V4      \        ^ V4       # )r   )r   maxr   s   &&&r   __getslice__DerSequence.__getslice__  s    yyQ3q!955r"   c                ,    \        V P                  4      # r$   r-   r   r%   s   &r   __len__DerSequence.__len__  s    499~%r"   c                <    V P                   P                  V4       V # r$   r   appendr   items   &&r   __iadd__DerSequence.__iadd__      		  &r"   c                <    V P                   P                  V4       V # r$   r   r   s   &&r   r   DerSequence.append  r   r"   c                <    V P                   P                  W4       V # r$   )r   insert)r   indexr   s   &&&r   r   DerSequence.insert  s    		  -r"   c                ~    V P                    Uu. uF  p\        W!4      '       g   K  VNK  	  pp\        V4      # u upi )zReturn the number of items in this sequence that are
integers.

Args:
  only_non_negative (boolean):
    If ``True``, negative integers are not counted in.
)r   r   r-   )r   r   r   itemss   &&  r   hasIntsDerSequence.hasInts!  s5     %)IIRIqA1QIR5z! Ss   ::c                x    V P                   ;'       d(    V P                  V4      \        V P                   4      8H  # )a9  Return ``True`` if all items in this sequence are integers
or non-negative integers.

This function returns False is the sequence is empty,
or at least one member is not an integer.

Args:
  only_non_negative (boolean):
    If ``True``, the presence of negative integers
    causes the method to return ``False``.)r   r   r-   )r   r   s   &&r   hasOnlyIntsDerSequence.hasOnlyInts-  s-     yyVVT\\2C%DDII%VVr"   c                   RV n         V P                   F  p\        V4      '       d   V ;P                   V,          un         K/  \        V4      '       d3   V ;P                   \	        V4      P                  4       ,          un         Kr  V ;P                   VP                  4       ,          un         K  	  \        P                  V 4      # )zReturn this DER SEQUENCE, fully encoded as a
binary string.

Raises:
  ValueError: if some elements in the sequence are neither integers
              nor byte strings.
r"   )rH   r   r   r   r	   rZ   r   r   s   & r   rZ   DerSequence.encode:  s      # IID"4((,#D))
4(8(?(?(AA5 & !''--r"   c                    W0n         \        P                  WVR7      pV'       d"   V P                  4       '       g   \	        R4      hV# )aI  Decode a complete DER SEQUENCE, and re-initializes this
object with it.

Args:
  der_encoded (byte string):
    A complete SEQUENCE DER element.
  nr_elements (None or integer or list of integers):
    The number of members the SEQUENCE can have
  only_ints_expected (boolean):
    Whether the SEQUENCE is expected to contain only integers.
  strict (boolean):
    Whether decoding must check for strict DER compliancy.

Raises:
  ValueError: in case of parsing errors.

DER INTEGERs are decoded into Python integers. Any other DER
element is not decoded. Its validity is not checked.
rz   zSome members are not INTEGERs)_nr_elementsr   rf   r   r1   )r   rd   re   nr_elementsonly_ints_expectedr4   s   &&&&& r   rf   DerSequence.decodeL  sA    * %0!"))$F)K%d.>.>.@.@$%DEEr"   c                .   . V n         \        P                  WV4       \        V P                  4      pVP                  4       ^ 8  d   VP                  4        \        4       pVP                  W24       VP                  ^8w  d,   V P                   P                  VP                  4       4       K|  \        4       pVP                  4       pVP                  WbR7       V P                   P                  VP                  4       K  RpV P                  e$    \        V P                   4      V P                  9   pV'       g&   \!        R\        V P                   4      ,          4      hR#   \         d&    \        T P                   4      T P                  8H  p L^i ; i)z+Decode a complete DER SEQUENCE from a file.rz   TNz1Unexpected number of members (%d) in the sequence)r   r   rc   r   rH   r.   r&   rF   r   r*   r	   rf   rr   r   r-   r   r1   )r   r]   re   rj   derderIntdataoks   &&&     r   rc   DerSequence._decodeFromStreami  sH    	 ++DV<  -&&(1,NN$#+C))!4 ~~-		(()>)>)@A!+ 446d:		((6$$0A ^t/@/@@ $ &8:=dii.&I J J  % A ^t/@/@@As   "E$ $-FF)r   r   rH   )NNN)T)FNF)r;   r<   r=   r>   r?   r    r   r   r   r   r   r   r   r   r   r   r   r   rZ   rf   rc   r@   rA   rB   s   @r   r   r     sc     (	T	)8	!	$	'	*	#	6	&			
	"	W	.$	:"	J "	Jr"   c                   .   a  ] tR tRt o RtRR ltRtV tR# )r   i  a  Class to model a DER OCTET STRING.

An example of encoding is:

>>> from Crypto.Util.asn1 import DerOctetString
>>> from binascii import hexlify, unhexlify
>>> os_der = DerOctetString(b'\xaa')
>>> os_der.payload += b'\xbb'
>>> print hexlify(os_der.encode())

which will show ``0402aabb``, the DER encoding for the byte string
``b'\xAA\xBB'``.

For decoding:

>>> s = unhexlify(b'0402aabb')
>>> try:
>>>   os_der = DerOctetString()
>>>   os_der.decode(s)
>>>   print hexlify(os_der.payload)
>>> except ValueError:
>>>   print "Not a valid DER OCTET STRING"

the output will be ``aabb``.

:ivar payload: The content of the string
:vartype payload: byte string
Nc                6    \         P                  V ^WR4       R# )a(  Initialize the DER object as an OCTET STRING.

:Parameters:
  value : byte string
    The initial payload of the object.
    If not specified, the payload is empty.

  implicit : integer
    The IMPLICIT tag to use for the encoded object.
    It overrides the universal tag for OCTET STRING (4).
FNr   r    )r   rr   rK   s   &&&r   r    DerOctetString.__init__  s     	4u>r"    )r"   Nr;   r<   r=   r>   r?   r    r@   rA   rB   s   @r   r   r     s     :? ?r"   c                   *   a  ] tR tRt o RtR tRtV tR# )r   i  z"Class to model a DER NULL element.c                8    \         P                  V ^RRR4       R# )z$Initialize the DER object as a NULL.r"   NFr   r%   s   &r   r    DerNull.__init__  s     	4sD%8r"   r   Nr   rB   s   @r   r   r     s     ,9 9r"   c                   D   a  ] tR tRt o RtR	R ltR tR
R ltR tRt	V t
R# )r   i  a  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:
>>>   print "Not a valid DER OBJECT ID"

the output will be ``1.2.840.113549.1.1.1``.

:ivar value: The Object ID (OID), a dot separated list of integers
:vartype value: string
Nc                F    \         P                  V ^RVRV4       Wn        R# )aJ  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).
  explicit : integer
    The EXPLICIT tag to use for the encoded object.
r"   FNrq   rs   s   &&&&r   r    DerObjectId.__init__  s!     	4sHeXF
r"   c                   V P                   P                  R4       Uu. uF  p\        V4      NK  	  pp\        V4      ^8  d   \	        R4      hV^ ,          ^8  d   \	        R4      hV^ ,          ^8  d   V^,          ^'8  d   \	        R4      h^(V^ ,          ,          V^,          ,           .VR,          ,           p. p\        V4       FV  pVP                  V^,          4       V^,          pV'       g   K.  VP                  V^,          ^,          4       V^,          pK4  	  RP                  \        V4       Uu. uF  p\        V4      NK  	  up4      V n	        \        P                  V 4      # u upi u upi )z;Return the DER OBJECT ID, fully encoded as a
binary string..z$Not a valid Object Identifier stringz!First component must be 0, 1 or 2z#Second component must be 39 at most:r   NNr"   )rr   splitrv   r-   r1   reversedr   joinr   rH   r   rZ   )r   r   compssubcompsrT   vs   &     r   rZ   DerObjectId.encode  s6    "&!1!1#!67!6AQ!67u:>CDD8a<@AA8a<E!HrMBCCqME!H,-b	9(#AOOAH%!GA!TT 12a $ xx(82D E2DQa2D EF%%) 8& !Fs   E0;E5c                .    \         P                  WV4      # )a  Decode a complete DER OBJECT ID, and re-initializes this
object with it.

Args:
    der_encoded (byte string):
        A complete DER OBJECT ID.
    strict (boolean):
        Whether decoding must check for strict DER compliancy.

Raises:
    ValueError: in case of parsing errors.
r{   r|   s   &&&r   rf   DerObjectId.decode  s     6::r"   c                t   \         P                  WV4       \        V P                  4      p. p^ pVP	                  4       '       dN   VP                  4       pV^,          V^,          ,           pV^,          '       d   KN  VP                  V4       ^ pKc  \        V4      ^ 8X  d   \        R4      hV^ ,          ^(8  d   ^ V^ ,          .VR&   M9V^ ,          ^P8  d   ^V^ ,          ^(,
          .VR&   M^V^ ,          ^P,
          .VR&   RP                  V Uu. uF  p\        V4      NK  	  up4      V n        R# u upi )z,Decode a complete DER OBJECT ID from a file.zEmpty payload:Nr8   Nr   N)r   rc   r   rH   r.   r9   r   r-   r1   r   strrr   )r   r]   re   rj   r   r   cr   s   &&&     r   rc   DerObjectId._decodeFromStream  s	    	##DV4 %  AaAH%AHH"x=A_--A;x{+HRLa[2x{R/0HRLx{R/0HRLXXx8x!s1vx89
8s   D5r   ) NNrm   r   rB   s   @r   r   r     s#     :&4; : :r"   c                   D   a  ] tR tRt o RtR	R ltR tR
R ltR tRt	V t
R# )r   i:  aV  Class to model a DER BIT STRING.

An example of encoding is:

>>> from Crypto.Util.asn1 import DerBitString
>>> bs_der = DerBitString(b'\xAA')
>>> bs_der.value += b'\xBB'
>>> print(bs_der.encode().hex())

which will show ``030300aabb``, the DER encoding for the bit string
``b'\xAA\xBB'``.

For decoding:

>>> s = bytes.fromhex('030300aabb')
>>> try:
>>>   bs_der = DerBitString()
>>>   bs_der.decode(s)
>>>   print(bs_der.value.hex())
>>> except ValueError:
>>>   print "Not a valid DER BIT STRING"

the output will be ``aabb``.

:ivar value: The content of the string
:vartype value: byte string
Nc                    \         P                  V ^RVRV4       \        V\         4      '       d   VP                  4       V n        R# Wn        R# )ay  Initialize the DER object as a BIT STRING.

:Parameters:
  value : byte string or DER object
    The initial, packed bit string.
    If not specified, the bit string is empty.
  implicit : integer
    The IMPLICIT tag to use for the encoded object.
    It overrides the universal tag for BIT STRING (3).
  explicit : integer
    The EXPLICIT tag to use for the encoded object.
r"   FN)r   r    
isinstancerZ   rr   rs   s   &&&&r   r    DerBitString.__init__W  s=     	4sHeXF eY''DJJr"   c                \    RV P                   ,           V n        \        P                  V 4      # )z:Return the DER BIT STRING, fully encoded as a
byte string.r   r   r%   s   &r   rZ   DerBitString.encodel  s%    
 +%%r"   c                .    \         P                  WV4      # )a  Decode a complete DER BIT STRING, and re-initializes this
object with it.

Args:
    der_encoded (byte string): a complete DER BIT STRING.
    strict (boolean):
        Whether decoding must check for strict DER compliancy.

Raises:
    ValueError: in case of parsing errors.
r{   r|   s   &&&r   rf   DerBitString.decodet  s     6::r"   c                   \         P                  WV4       V P                  '       d-   \        V P                  ^ ,          4      ^ 8w  d   \	        R4      hRV n        V P                  '       d   V P                  R,          V n        R# R# )z1Decode a complete DER BIT STRING DER from a file.zNot a valid BIT STRINGr"   :r8   NNN)r   rc   rH   r   r1   rr   r   s   &&&r   rc   DerBitString._decodeFromStream  sd     	##DV4<<<Da1Q6566 
<<<b)DJ r"   r   )r"   NNrm   r   rB   s   @r   r   r   :  s#     8*&;* *r"   c                   \   a  ] tR tRt o RtRR ltR tR tR tR t	RR	 lt
R
 tR tRtV tR# )r   i  a=  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:
>>>   print "Not a valid DER SET OF"

the output will be ``[4, 5, 6]``.
Nc                    \         P                  V ^RVR4       . V n        RV n        V'       d   V F  pV P	                  V4       K  	  R# R# )a  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).
r"   TN)r   r    r   
_elemOctetadd)r   startSetrK   es   &&& r   r    DerSetOf.__init__  sG     	4sHd;	   r"   c                (    V P                   V,          # r$   r   r   s   &&r   r   DerSetOf.__getitem__  s    yy|r"   c                ,    \        V P                  4      # r$   )iterr   r%   s   &r   __iter__DerSetOf.__iter__  s    DIIr"   c                ,    \        V P                  4      # r$   r   r%   s   &r   r   DerSetOf.__len__  s    499~r"   c                R   \        V4      '       d   ^pM5\        V\        4      '       d   V P                  pM\	        V^ ,          4      pV P
                  V8w  d    V P
                  e   \        R4      hW n        WP                  9  d   V P                  P                  V4       R# R# )zAdd an element to the set.

Args:
    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.
Nz&New element does not belong to the set)	r   r   r   rF   r   r  r1   r   r   )r   elemeos   && r   r  DerSetOf.add  s     dBi((Bd1gB??b * !IJJ Oyy IIT" !r"   c                .    \         P                  WV4      # )a  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.

Args:
    der_encoded (byte string): a complete DER BIT SET OF.
    strict (boolean):
        Whether decoding must check for strict DER compliancy.

Raises:
    ValueError: in case of parsing errors.
r{   r|   s   &&&r   rf   DerSetOf.decode  s      6::r"   c                R   . V n         \        P                  WV4       \        V P                  4      pRpVP                  4       ^ 8  d   VP                  4        \        4       pVP                  W24       V^ 8  d   VP                  pMWEP                  8w  d   \        R4      hV^8w  d,   V P                   P                  VP                  4       4       K  \        4       pVP                  VP                  4       V4       V P                   P                  VP                  4       K  R# )z)Decode a complete DER SET OF from a file.z)Not all elements are of the same DER typeN)r   r   rc   r   rH   r.   r&   rF   r1   r   r*   r	   rf   rr   )r   r]   re   rj   
setIdOctetr   r   s   &&&    r   rc   DerSetOf._decodeFromStream  s     	 	##DV4 %
 1$NN+C!!!, A~ ^^
/$%PQQ T!		  !6!6!89#a335v>		  .' %r"   c                l   . pV P                    Fh  p\        V4      '       d   \        V4      P                  4       pM)\	        V\
        4      '       d   VP                  4       pMTpVP                  V4       Kj  	  VP                  4        RP                  V4      V n	        \
        P                  V 4      # )zBReturn this SET OF DER element, fully encoded as a
binary string.
r"   )
r   r   r	   rZ   r   r   r   sortr   rH   )r   orderedr   byss   &   r   rZ   DerSetOf.encode  s     IID$ &--/D),,kkmNN3  	xx(%%r"   )r  r   rH   )NNrm   )r;   r<   r=   r>   r?   r    r   r  r   r  rf   rc   rZ   r@   rA   rB   s   @r   r   r     s8     4*#0;$/B& &r"   )	r   r	   r
   r   r   r   r   r   r   rm   )r   Crypto.Util.py3compatr   r   r   Crypto.Util.numberr   r   __all__r   objectr   r   r	   r
   r   r   r   r   r   r   r   r"   r   <module>r"     s   .  9 9 ;P+%& %@sZ sZl\' \'~P@ P@fRJ) RJj*?Y *?Z9i 9s:) s:lV*9 V*rU&y U&r"   