
    mg_                        U d Z ddlmZmZmZmZmZmZmZm	Z	 ddlm
Z
 ed   Z edd      ZdZdZd	Zd
ZdZdZd	Zd
ZdZdZdZdZdZdZdZdZi Zeeef   ed<   i Z ee	e!ef   ef   ed<   dede"dede#fdZ$ G d de%      Z& G d de&      Z' G d de&      Z( G d  d      Z) G d! d"      Z* G d# d$      Z+ G d% d&      Z, e*e e-d'      f       G d( d)e)             Z. e*ee"f       G d* d+e)             Z/ e*eef       G d, d-e)             Z0 e*ee#e1f       G d. d/e)             Z2 e*ee3f       G d0 d1e)             Z4 e*ee5e6fd23       G d4 d5e)             Z7 e*ee8e9fd23       G d6 d7e)             Z: e*e       G d8 d9e)             Z; e*e       G d: d;e)             Z< e*e       G d< d=e)             Z=d>e!de#fd?Z>d@e#dee!ef   fdAZ?d@e#de!fdBZ@y')CaJ  Utilities for encoding and decoding ASN.1 DER data

   The der_encode function takes a Python value and encodes it in DER
   format, returning a byte string. In addition to supporting standard
   Python types, BitString can be used to encode a DER bit string,
   ObjectIdentifier can be used to encode OIDs, values can be wrapped
   in a TaggedDERObject to set an alternate DER tag on them, and
   non-standard types can be encoded by placing them in a RawDERObject.

   The der_decode function takes a byte string in DER format and decodes
   it into the corresponding Python values.

    )Dict	FrozenSetSequenceSetTupleTypeTypeVarUnion)castDERType_DERClassVar	_DERClass)bound                              )	UniversalApplicationzContext-specificPrivate_der_class_by_tag_der_class_by_type
asn1_classconstructedtagreturnc                    | t         t        t        t        fvrt	        d      | dz  |rdndz  }|dk  r||z  g}nA|dz  g}|dk\  r"|dz  }|j                  d|dz  z         |dk\  r"|j                  |dz         t        |d	d	d
         S )z Encode a DER object's identifierzInvalid ASN.1 classr       r               N)	UNIVERSALAPPLICATIONCONTEXT_SPECIFICPRIVATEASN1EncodeErrorappendbytes)r   r    r!   flags
identifiers        -lib/python3.12/site-packages/asyncssh/asn1.py_encode_identifierr4   D   s     )[2BGLL3441_$?E
Tzck]
Dj\
TkAICdcDj12 Tk 	%$,'DbD!""    c                       e Zd ZdZy)	ASN1ErrorzASN.1 coding errorN__name__
__module____qualname____doc__ r5   r3   r7   r7   Z   s    r5   r7   c                       e Zd ZdZy)r.   zASN.1 DER encoding errorNr8   r=   r5   r3   r.   r.   ^       "r5   r.   c                       e Zd ZdZy)ASN1DecodeErrorzASN.1 DER decoding errorNr8   r=   r5   r3   rA   rA   b   r?   r5   rA   c                   X    e Zd ZU dZdZeed<   ededefd       Z	e
dededefd	       Zy
)r   z3Parent class for classes which use DERTag decoratorr5   r2   valuer"   c                     t         )z!Encode value as a DER byte stringNotImplementedErrorrC   s    r3   encodezDERType.encodek   
     "!r5   r    contentc                     t         )z'Decode a DER byte string into an objectrE   clsr    rJ   s      r3   decodezDERType.decodeq   rI   r5   N)r9   r:   r;   r<   r2   r0   __annotations__staticmethodobjectrH   classmethodboolrN   r=   r5   r3   r   r   f   sX    =J"f " " "
 " " "& " "r5   c                   @    e Zd ZdZ	 	 d
dedee   defdZde	de	fdZ
y	)DERTagaa  A decorator used by classes which convert values to/from DER

       Classes which convert Python values to and from DER format
       should use the DERTag decorator to indicate what DER tag value
       they understand. When DER data is decoded, the tag is looked
       up in the list to see which class to call to perform the
       decoding.

       Classes which convert existing Python types to and from DER
       format can specify the list of types they understand in the
       optional "types" argument. Otherwise, conversion is expected
       to be to and from the new class being defined.

    r!   typesr    c                 L    || _         || _        t        t        ||      | _        y N)_tag_typesr4   r*   _identifier)selfr!   rV   r    s       r3   __init__zDERTag.__init__   s!    	-icJr5   rM   r"   c                     | j                   |_        |t        | j                  <   | j                  r| j                  D ]  }|t
        |<    |S |t
        |<   |S rX   )r[   r2   r   rY   rZ   r   )r\   rM   ts      r3   __call__zDERTag.__call__   sW    ))'*$))$;;[[(+"1% !
 
 '*s#
r5   N)r=   F)r9   r:   r;   r<   intr   rQ   rS   r]   r   r`   r=   r5   r3   rU   rU   x   sF     <>%*KC K(8 K"KL \ r5   rU   c                   r    e Zd ZdZdededefdZdefdZde	de
fd	Zdefd
ZdefdZede	defd       Zy)RawDERObjecta7  A class which can encode a DER object of an arbitrary type

       This object is initialized with an ASN.1 class, tag, and a
       byte string representing the already encoded data. Such
       objects will never have the constructed flag set, since
       that is represented here as a TaggedDERObject.

    r!   rJ   r   c                 .    || _         || _        || _        y rX   )r   r!   rJ   )r\   r!   rJ   r   s       r3   r]   zRawDERObject.__init__   s    $r5   r"   c                 d    dt         | j                     d| j                  d| j                  dS )NzRawDERObject(, ))_asn1_classr   r!   rJ   r\   s    r3   __repr__zRawDERObject.__repr__   s&    T__-txxG 	Hr5   otherc                     t        |t              st        S | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S rX   )
isinstancerc   NotImplementedr   r!   rJ   r\   rk   s     r3   __eq__zRawDERObject.__eq__   sV    %.!!5#3#33 HEII%H*.,,%--*G	Ir5   c                 Z    t        | j                  | j                  | j                  f      S rX   )hashr   r!   rJ   ri   s    r3   __hash__zRawDERObject.__hash__   s     T__dhh=>>r5   c                 D    t        | j                  d| j                        S ):Encode the DER identifier for this object as a byte stringFr4   r   r!   ri   s    r3   encode_identifierzRawDERObject.encode_identifier   s     "$//5$((CCr5   rC   c                 .    t        d|       j                  S )7Encode the content for this object as a DER byte stringrc   )r   rJ   rG   s    r3   rH   zRawDERObject.encode   s     NE*222r5   N)r9   r:   r;   r<   ra   r0   r]   strrj   rQ   rS   rp   rs   rw   rP   rH   r=   r5   r3   rc   rc      s    C % S 
H# HIF It I?# ?D5 D
 3f 3 3 3r5   rc   c                   v    e Zd ZdZefdededefdZdefdZ	dede
fd	Zdefd
ZdefdZededefd       Zy)TaggedDERObjectau  An explicitly tagged DER object

       This object provides a way to wrap an ASN.1 object with an
       explicit tag. The value (including the tag representing its
       actual type) is then encoded as part of its value. By
       default, the ASN.1 class for these objects is CONTEXT_SPECIFIC,
       and the DER encoding always marks these values as constructed.

    r!   rC   r   c                 .    || _         || _        || _        y rX   )r   r!   rC   )r\   r!   rC   r   s       r3   r]   zTaggedDERObject.__init__   s    $
r5   r"   c                     | j                   t        k(  rd| j                  d| j                  dS dt        | j                      d| j                  d| j                  dS )NzTaggedDERObject(rf   rg   )r   r,   r!   rC   rh   ri   s    r3   rj   zTaggedDERObject.__repr__   sM    ??..04$**EE / !1488TZZI Jr5   rk   c                     t        |t              st        S | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S rX   )rm   r|   rn   r   r!   rC   ro   s     r3   rp   zTaggedDERObject.__eq__   sV    %1!!5#3#33 DEII%D*.***C	Er5   c                 Z    t        | j                  | j                  | j                  f      S rX   )rr   r   r!   rC   ri   s    r3   rs   zTaggedDERObject.__hash__   s     T__dhh

;<<r5   c                 D    t        | j                  d| j                        S )ru   Trv   ri   s    r3   rw   z!TaggedDERObject.encode_identifier   s     "$//4BBr5   c                 @    t        t        d|       j                        S )ry   r|   )
der_encoder   rC   rG   s    r3   rH   zTaggedDERObject.encode   s     $0%8>>??r5   N)r9   r:   r;   r<   r,   ra   rQ   r]   rz   rj   rS   rp   rs   r0   rw   rP   rH   r=   r5   r3   r|   r|      s     $4C   J# JEF Et E=# =C5 C
 @f @ @ @r5   r|   Nc                   H    e Zd ZdZededefd       Zede	deddfd       Z
y)	_NullzA null valuerC   r"   c                      y)zEncode a DER null valuer5   r=   rG   s    r3   rH   z_Null.encode   s     r5   r    rJ   Nc                 8    |rt        d      |rt        d      y)zDecode a DER null valuezNULL should not be constructedz'NULL should not have associated contentNrA   rL   s      r3   rN   z_Null.decode   s%     !"BCC!"KLLr5   r9   r:   r;   r<   rP   rQ   r0   rH   rR   rS   rN   r=   r5   r3   r   r      sN    f    	 	 	$ 	 	r5   r   c                   H    e Zd ZdZededefd       Zede	dede	fd       Z
y)	_BooleanzA boolean valuerC   r"   c                     | rdS dS )zEncode a DER boolean value       r=   rG   s    r3   rH   z_Boolean.encode  s      w*U*r5   r    rJ   c                 V    |rt        d      |dvrt        d      t        |d         S )zDecode a DER boolean valuez!BOOLEAN should not be constructed>   r   r   z$BOOLEAN content must be 0x00 or 0xffr   )rA   rS   rL   s      r3   rN   z_Boolean.decode  s7     !"EFF,,!"HIIGAJr5   Nr   r=   r5   r3   r   r     sN    +f + + +
 	  	  	 $ 	  	 r5   r   c                   H    e Zd ZdZededefd       Zede	dede
fd       Zy)	_IntegerzAn integer valuerC   r"   c                     t        t        |       }|j                         }|dz  dk(  r|dz  dz   n|dz   dz  }|j                  |dd      }|j	                  d      r|dd	 S |S )
zEncode a DER integer value   r   r   r'   bigTsigneds   N)r   ra   
bit_lengthto_bytes
startswith)rC   ilresults       r3   rH   z_Integer.encode'  sn     eLLNa%1*AFQJ1q5Q,AuT2#..{;vabzGGr5   r    rJ   c                 L    |rt        d      t        j                  |dd      S )zDecode a DER integer valuez!INTEGER should not be constructedr   Tr   )rA   ra   
from_bytesrL   s      r3   rN   z_Integer.decode1  s(     !"EFF~~guT~::r5   N)r9   r:   r;   r<   rP   rQ   r0   rH   rR   rS   ra   rN   r=   r5   r3   r   r   #  sR    Hf H H H ; ; ;# ; ;r5   r   c                   H    e Zd ZdZededefd       Zede	dedefd       Z
y)	_OctetStringzAn octet string valuerC   r"   c                 "    t        t        |       S )zEncode a DER octet string)r   r0   rG   s    r3   rH   z_OctetString.encode?  s     E5!!r5   r    rJ   c                      |rt        d      |S )zDecode a DER octet stringz&OCTET STRING should not be constructedr   rL   s      r3   rN   z_OctetString.decodeE  s     !"JKKr5   Nr   r=   r5   r3   r   r   ;  sN    "f " " "
   %  r5   r   c                   H    e Zd ZdZededefd       Zede	dede
fd       Zy)	_UTF8StringzA UTF-8 string valuerC   r"   c                 @    t        t        |       j                  d      S )zEncode a DER UTF-8 stringutf-8)r   rz   rH   rG   s    r3   rH   z_UTF8String.encodeS  s     C&&w//r5   r    rJ   c                 >    |rt        d      |j                  d      S )zDecode a DER UTF-8 stringz%UTF8 STRING should not be constructedr   )rA   rN   rL   s      r3   rN   z_UTF8String.decodeY  s"     !"IJJ~~g&&r5   N)r9   r:   r;   r<   rP   rQ   r0   rH   rR   rS   rz   rN   r=   r5   r3   r   r   O  sN    0f 0 0 0
 ' ' '# ' 'r5   r   T)r    c                   N    e Zd ZdZededefd       Zede	dede
e   fd       Zy)		_SequencezA sequence of valuesrC   r"   c                 `    t        t        t           |       }dj                  d |D              S )zEncode a sequence of DER valuesr5   c              3   2   K   | ]  }t        |        y wrX   r   .0items     r3   	<genexpr>z#_Sequence.encode.<locals>.<genexpr>l  s     ?YT
4(Y   )r   r   rQ   join)rC   	seq_values     r3   rH   z_Sequence.encodeg  s*     &)51	xx?Y???r5   r    rJ   c                     |st        d      d}t        |      }g }||k  r-t        ||d       \  }}|j                  |       ||z  }||k  r-t	        |      S )zDecode a sequence of DER valuesz%SEQUENCE should always be constructedr   N)rA   lender_decode_partialr/   tuplerM   r    rJ   offsetlengthrC   r   consumeds           r3   rN   z_Sequence.decoden  sm     !"IJJWvo/0@AND(LLhF vo
 U|r5   N)r9   r:   r;   r<   rP   rQ   r0   rH   rR   rS   r   rN   r=   r5   r3   r   r   c  sW    @f @ @ @   (6:J  r5   r   c                   N    e Zd ZdZededefd       Zede	dede
e   fd       Zy)	_SetzA set of DER valuesrC   r"   c                     t        t        t        t           t        t           f   |       }dj                  t        d |D                    S )zEncode a set of DER valuesr5   c              3   2   K   | ]  }t        |        y wrX   r   r   s     r3   r   z_Set.encode.<locals>.<genexpr>  s     FIDz$/Ir   )r   r
   r   rQ   r   r   sorted)rC   	set_values     r3   rH   z_Set.encode  s=     y0#f+=>F	xxFIFFGGr5   r    rJ   c                     |st        d      d}t        |      }t               }||k  r-t        ||d       \  }}|j	                  |       ||z  }||k  r-t        |      S )zDecode a set of DER valuesz SET should always be constructedr   N)rA   r   setr   add	frozensetr   s           r3   rN   z_Set.decode  so     !"DEEWvo/0@AND(IIdOhF vo
 r5   N)r9   r:   r;   r<   rP   rQ   r0   rH   rR   rS   r   rN   r=   r5   r3   r   r     sW    Hf H H H      )F:K    r5   r   c                       e Zd ZdZddededefdZdefdZ	defdZ
d	edefd
ZdefdZededefd       Zedededd fd       Zy)	BitStringa  A string of bits

       This object can be initialized either with a byte string and an
       optional count of the number of least-significant bits in the last
       byte which should not be included in the value, or with a string
       consisting only of the digits '0' and '1'.

       An optional 'named' flag can also be set, indicating that the
       BitString was specified with named bits, indicating that the proper
       DER encoding of it should strip any trailing zeroes.

    rC   unusednamedc           	         |dk  s|dkD  rt        d      t        t              r(|rst        d      d   d|z  dz
  z  r{t        d      t        t              rU|rt        d      t	              d	z  }|rd	|z
  nd}|d
z  z  t        fdt        dt	              d	      D              nt        d      |r,r*d   d|z  z  s|dz  }|d	k(  rd d d}rd   d|z  z  s| _        || _        y )Nr   r'   z(Unused bit count must be between 0 and 7z'Can't have unused bits with empty valuer)   r   z#Unused bits in value should be zeroz:Unused bit count should not be set when providing a stringr   0c              3   B   K   | ]  }t        ||d z    d        yw)r   r   N)ra   )r   r   rC   s     r3   r   z%BitString.__init__.<locals>.<genexpr>  s*      <#:a eAaclA.#:s   z#Unexpected type of bit string value)r.   rm   r0   rz   r   rangerC   r   )r\   rC   r   r   useds    `   r3   r]   zBitString.__init__  s<   A:!!"LMMeU#) +2 3 32Y1;!"34) +1 2 2s#% '@ A A u:>D!%QX1FVc\!E <#(CJ#:< <E ""GHHb	Q&[ 9!Q;!#2JEF	 b	Q&[ 9 
r5   r"   c                     dj                  d | j                  D              }| j                  r|d | j                    }|S )N c              3   V   K   | ]!  }t        |      d d j                  d       # yw)r   Nr   )binzfill)r   bs     r3   r   z$BitString.__str__.<locals>.<genexpr>  s&     AjQ))!,js   '))r   rC   r   )r\   r   s     r3   __str__zBitString.__str__  s8    AdjjAA;;Mdkk\*Fr5   c                     d| z  S )NzBitString('%s')r=   ri   s    r3   rj   zBitString.__repr__  s     4''r5   rk   c                     t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S rX   )rm   r   rn   rC   r   ro   s     r3   rp   zBitString.__eq__  s7    %+!!zzU[[(HT[[ELL-HHr5   c                 D    t        | j                  | j                  f      S rX   )rr   rC   r   ri   s    r3   rs   zBitString.__hash__  s    TZZ-..r5   c                 `    t        d|       }t        |j                  f      |j                  z   S )zEncode a DER bit stringr   )r   r0   r   rC   )rC   bitstr_values     r3   rH   zBitString.encode  s/     K/l))+,|/A/AAAr5   r    rJ   c                 f    |rt        d      |r|d   dkD  rt        d       | |dd |d         S )zDecode a DER bit stringz$BIT STRING should not be constructedr   r'   zInvalid unused bit countr   N)r   r   rL   s      r3   rN   zBitString.decode  sC     !"HII'!*q.!"<==712;wqz22r5   N)r   F)r9   r:   r;   r<   rQ   ra   rS   r]   rz   r   rj   rp   rs   rP   r0   rH   rR   rN   r=   r5   r3   r   r     s    !f !c !d !F (# (IF It I/# / Bf B B B 	3 	3 	3+ 	3 	3r5   r   c                       e Zd ZdZdeeef   fdZdefdZ	defdZ
dedefdZdefd	Zededefd
       Zedededd fd       Zy)	IA5StringzAn ASCII string valuerC   c                     || _         y rX   rG   r\   rC   s     r3   r]   zIA5String.__init__  	    
r5   r"   c                 >    d| j                   j                  d      z  S )Nz%sascii)rC   rN   ri   s    r3   r   zIA5String.__str__  s    djj''000r5   c                      d| j                   z  S )NzIA5String(%r)rG   ri   s    r3   rj   zIA5String.__repr__  s    ++r5   rk   c                 `    t        |t              st        S | j                  |j                  k(  S rX   )rm   r   rn   rC   ro   s     r3   rp   zIA5String.__eq__  s%    %+!!zzU[[((r5   c                 ,    t        | j                        S rX   rr   rC   ri   s    r3   rs   zIA5String.__hash__
      DJJr5   c                 .    t        d|       j                  S )zEncode a DER IA5 stringr   )r   rC   rG   s    r3   rH   zIA5String.encode  s     K'---r5   r    rJ   c                 ,    |rt        d       | |      S )zDecode a DER IA5 stringz$IA5 STRING should not be constructedr   rL   s      r3   rN   zIA5String.decode  s     !"HII 7|r5   N)r9   r:   r;   r<   r
   r0   	bytearrayr]   rz   r   rj   rQ   rS   rp   ra   rs   rP   rH   rR   rN   r=   r5   r3   r   r     s    eE9$45 1 1,# ,)F )t ) #   	.f 	. 	. 	. 
 
 
+ 
 
r5   r   c                       e Zd ZdZdefdZdefdZdefdZdede	fdZ
defd	Zededefd
       Zede	dedd fd       Zy)ObjectIdentifiera  An object identifier (OID) value

       This object can be initialized from a string of dot-separated
       integer values, representing a hierarchical namespace. All OIDs
       show have at least two components, with the first being between
       0 and 2 (indicating ITU-T, ISO, or joint assignment). In cases
       where the first component is 0 or 1, the second component must
       be in the range 0 to 39 due to the way these first two components
       are encoded.

    rC   c                     || _         y rX   rG   r   s     r3   r]   zObjectIdentifier.__init__5  r   r5   r"   c                     | j                   S rX   rG   ri   s    r3   r   zObjectIdentifier.__str__8  s    zzr5   c                      d| j                   z  S )NzObjectIdentifier('%s')rG   ri   s    r3   rj   zObjectIdentifier.__repr__;  s    '$**44r5   rk   c                 `    t        |t              st        S | j                  |j                  k(  S rX   )rm   r   rn   rC   ro   s     r3   rp   zObjectIdentifier.__eq__>  s&    %!12!!zzU[[((r5   c                 ,    t        | j                        S rX   r   ri   s    r3   rs   zObjectIdentifier.__hash__D  r   r5   c                    dt         dt        fdt        d|       }	 |j                  j	                  d      D cg c]  }t        |       }}t        |      dk  rt        d	      |d
   d
k  s|d
   dkD  rt        d      |d
   dk  r|d   d
k  s|d   dkD  rt        d      |d
   dz  |d   z   g|d
d dj                  fd|D              S c c}w # t
        $ r t        d      dw xY w)zEncode a DER object identifier	componentr"   c                     | dk  rt        d      | dz  g}| dk\  r"| dz  } |j                  d| dz  z         | dk\  r"t        |ddd         S )z7Convert a single element of an OID to a DER byte stringr   zBComponents of object identifier must be greater than or equal to 0r%   r&   r'   Nr)   )r.   r/   r0   )r   r   s     r3   _bytesz'ObjectIdentifier.encode.<locals>._bytesK  su     1}% 'F G G  $&'Ft#a	di$&678 t# "&&r5   r   .z!Component values must be integersNr   z4Object identifiers must have at least two componentsr   z<First component of object identifier must be between 0 and 2r   '   z>Second component of object identifier must be between 0 and 39(   r5   c              3   .   K   | ]  } |        y wrX   r=   )r   cr   s     r3   r   z*ObjectIdentifier.encode.<locals>.<genexpr>l  s     6:aq	:s   )	ra   r0   r   rC   split
ValueErrorr.   r   r   )rC   	oid_valuer   
componentsr   s       @r3   rH   zObjectIdentifier.encodeG  s1   	'c 	'e 	' +U3		8*3//*?*?*DE*DQ#a&*DJE
 z?Q! #/ 0 0]Q*Q-!"3! #7 8 8]QJqMA$5A9K! #8 9 9 &a=+jm;<
1Qxx6:666! F 	8! #- .378	8s   C CC C C.r    rJ   c                 l   |rt        d      |st        d      |d   }|dk  rt        t        |d            nd|dz
  g}d}|dd D ]@  }|d	k(  r|dk(  rt        d
      |d	k  r|j                  ||z         d}4||dz  z  }|dz  }B |rt        d       | dj	                  d |D                    S )zDecode a DER object identifierz+OBJECT IDENTIFIER should not be constructedzEmpty object identifierr   P   r   r   r   Nr&   zInvalid componentr%   r'   zIncomplete componentr   c              3   2   K   | ]  }t        |        y wrX   )rz   )r   r   s     r3   r   z*ObjectIdentifier.decode.<locals>.<genexpr>  s     7JqCFJr   )rA   listdivmodr/   r   )rM   r    rJ   r   r   r   s         r3   rN   zObjectIdentifier.decoden  s     ! #0 1 1 !";<<AJ,-FT&B-(AbD	
	ADyY!^%&9::T!!)a-0	QX%	a	  !"8993887J7788r5   N)r9   r:   r;   r<   rz   r]   r   rj   rQ   rS   rp   ra   rs   rP   r0   rH   rR   rN   r=   r5   r3   r   r   '  s    
c  5# 5)F )t ) #   $7f $7 $7 $7L 9 9 9:L 9 9r5   r   rC   c                    t        |       }|t        t        fv r?t        t        t        t        f   |       } | j                         }| j                  |       }nG|t        v r't        |   }|j                  }|j                  |       }nt        d|j                  z        t        |      }|dk  rt        |f      }nA|j                  |j                         dz   dz  d      }t        dt        |      z  f      |z   }||z   |z   S )a0  Encode a value in DER format

       This function takes a Python value and encodes it in DER format.
       The following mapping of types is used:

       NoneType            -> NULL
       bool                -> BOOLEAN
       int                 -> INTEGER
       bytes, bytearray    -> OCTET STRING
       str                 -> UTF8 STRING
       list, tuple         -> SEQUENCE
       set, frozenset      -> SET
       BitString           -> BIT STRING
       ObjectIdentifier    -> OBJECT IDENTIFIER

       An explicitly tagged DER object can be encoded by passing in a
       TaggedDERObject which specifies the ASN.1 class, tag, and value
       to encode.

       Other types can be encoded by passing in a RawDERObject which
       specifies the ASN.1 class, tag, and raw content octets to encode.

    zCannot DER encode type %sr&   r'   r   r   )typerc   r|   r   r
   rw   rH   r   r2   r.   r9   r   r0   r   r   )rC   r_   r2   rJ   rM   r   	len_bytess          r3   r   r     s    2 	UA\?++U<895A,,.
,,u%	
 	  #^^
**U#9AJJFGG\F}6)$	OOV%6%6%81%<$BEJ	4#i.023i?		!G++r5   datac                    t        |       dk  rt        d      | d   }|dz	  t        |dz        |dz  }}}d}|dk(  r5d}| |d D ]   }|dz  }|d	k  r||z  } n||d
z  z  }|dz  }" t        d      |t        |       k\  rt        d      | |   }|dz  }|d	kD  r'|d
z  }t        j	                  | |||z    d      }||z  }n|d	k(  rt        d      ||z   }| || }	|t        |       kD  rt        d      |t
        k(  r'|t        v rt        |   }
|
j                  ||	      }||fS |rt        |t        |	      |      }||fS t        ||	|      }||fS )zDDecode a value in DER format and return the number of bytes consumedr   zIncomplete datar   r   r$   r(   r   Nr&   r%   r'   zIncomplete tagr   zIndefinite length not allowed)r   rA   rS   ra   r   r*   r   rN   r|   
der_decoderc   )r  r!   r   r    r   r   r   len_sizeendrJ   rM   rC   s               r3   r   r     s    4y1}/00
q'C#&!8T#*-=sTzSJF
d{fgAaKF4xqq4x	  ""233T/00&\F
aKF}D=VF8O <eD(	4=>>
6/C6#G
SY/00Y3*;#;$

;0 #: 
Z%8*E #: S':6#:r5   c                 T    t        |       \  }}|t        |       k  rt        d      |S )a  Decode a value in DER format

       This function takes a byte string in DER format and converts it
       to a corresponding set of Python objects. The following mapping
       of ASN.1 tags to Python types is used:

       NULL              -> NoneType
       BOOLEAN           -> bool
       INTEGER           -> int
       OCTET STRING      -> bytes
       UTF8 STRING       -> str
       SEQUENCE          -> tuple
       SET               -> frozenset
       BIT_STRING        -> BitString
       OBJECT IDENTIFIER -> ObjectIdentifier

       Explicitly tagged objects are returned as type TaggedDERObject,
       with fields holding the object class, tag, and tagged value.

       Other object tags are returned as type RawDERObject, with fields
       holding the object class, tag, and raw content octets.

       If partial_ok is True, this function returns a tuple of the decoded
       value and number of bytes consumed. Otherwise, all data bytes must
       be consumed and only the decoded value is returned.

    z%Data contains unexpected bytes at end)r   r   rA   )r  rC   r  s      r3   r	  r	    s.    : $D)JE3
SYEFFLr5   )Ar<   typingr   r   r   r   r   r   r	   r
   r   r   r   r*   r+   r,   r-   END_OF_CONTENTBOOLEANINTEGER
BIT_STRINGOCTET_STRINGNULLOBJECT_IDENTIFIERUTF8_STRINGSEQUENCESET
IA5_STRINGrh   r   ra   rO   r   rQ   rS   r0   r4   r   r7   r.   rA   r   rU   rc   r|   r  r   r   r   r   r   rz   r   r  r   r   r   r   r   r   r   r   r   r   r	  r=   r5   r3   <module>r     s  * O N N  O	~[9 	  
 
I*, 4Y' ,@B Dvy019<= B#3 #T # # #,
 #i ##i #" "$! !H&3 &3R+@ +@\ tDzmG  0 $ w    , #;w ; ;. ui()7  *& cV'' ' '& 4-T2  3: c940 7   1 : 
T3 T3 T3n 
, , ,^ b9w b9 b9J,,f ,, ,,^1U 1uVS['9 1h"U "v "r5   