
    [Ah<@                     
   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJrJ	r	  SSK
JrJr   " S S\5      rS	 rSS
 jrS r\" 5       r\4S jrS rS rS rS rS rS rSS jrS rS rS rS rS r S r!S r"\4S jr#S r$S r%g)    )divisionN)chain)int2byte	text_type   )compat26_strstr_idx_as_intc                       \ rS rSrSrg)UnexpectedDER    N)__name__
__module____qualname____firstlineno____static_attributes__r       PC:\Users\julio\Documents\inmobiliaria_backend\env\Lib\site-packages\ecdsa/der.pyr   r      s    r   r   c                 N    [        SU -   5      [        [        U5      5      -   U-   $ )N   )r   encode_lengthlen)tagvalues     r   encode_constructedr      s$    D3J-E
";;eCCr   c                     US;  a  [        S5      eU S:  a  [        S5      eUS:X  a  SnOUS:X  a  SnO
US	:X  d   eS
n[        X0-   5      [        [        U5      5      -   U-   $ )a  
Encode and IMPLICIT value using :term:`DER`.

:param int tag: the tag value to encode, must be between 0 an 31 inclusive
:param bytes value: the data to encode
:param str cls: the class of the tag to encode: "application",
  "context-specific", or "private"
:rtype: bytes
)applicationcontext-specificprivatezinvalid tag class   zLong tags not supportedr   @   r      r      )
ValueErrorr   r   r   )r   r   cls	tag_classs       r   encode_implicitr'      sz     @@,--
Rx233
m		"	"	i	IO$}SZ'@@5HHr   c                 ,   U S:  d   eSU -  R                  5       n[        U5      S-  (       a  SU-   n[        R                  " U5      n[	        US5      nUS::  a  S[        [        U5      5      -   U-   $ S[        [        U5      S-   5      -   S-   U-   $ )	Nr   %x      0      r       )encoder   binascii	unhexlifyr	   r   )rhsnums       r   encode_integerr6   -   s    6M6	A
1vz1H1A
A
C
d{s1v..22
 s1vz22W<q@@r   c                 h   SnSnU[         L a  [        R                  " S[        5        OjUbg  SUs=::  a  S::  d  O  [	        S5      eU(       a9  U (       d  [	        S5      e[        U S5      nUSU-  S	-
  -  (       a  [	        S
5      e[        U5      nS	nS[        [        U 5      U-   5      -   U-   U -   $ )a5  
Encode a binary string as a BIT STRING using :term:`DER` encoding.

Note, because there is no native Python object that can encode an actual
bit string, this function only accepts byte strings as the `s` argument.
The byte string is the actual bit string that will be encoded, padded
on the right (least significant bits, looking from big endian perspective)
to the first full byte. If the bit string has a bit length that is multiple
of 8, then the padding should not be included. For correct DER encoding
the padding bits MUST be set to 0.

Number of bits of padding need to be provided as the `unused` parameter.
In case they are specified as None, it means the number of unused bits
is already encoded in the string as the first byte.

The deprecated call convention specifies just the `s` parameters and
encodes the number of unused bits as first parameter (same convention
as with None).

Empty string must be encoded with `unused` specified as 0.

Future version of python-ecdsa will make specifying the `unused` argument
mandatory.

:param s: bytes to encode
:type s: bytes like object
:param unused: number of bits at the end of `s` that are unused, must be
    between 0 and 7 (inclusive)
:type unused: int or None

:raises ValueError: when `unused` is too large or too small

:return: `s` encoded using DER
:rtype: bytes
r   r   z:Legacy call convention used, unused= needs to be specified   z&unused must be integer between 0 and 7z!unused is non-zero but s is emptyr*   r   z unused bits must be zeros in DER   )	_sentrywarningswarnDeprecationWarningr$   r	   r   r   r   )r4   unusedencoded_unused	len_extralasts        r   encode_bitstringrC   B   s    H NIH	
 
	FaEFF !DEE!!R(Dq&y1}% !CDD!&)	]3q6I#566G!KKr   c                 6    S[        [        U 5      5      -   U -   $ )N   )r   r   )r4   s    r   encode_octet_stringrF   {   s    ]3q6**Q..r   c                     SU s=::  a  S:  a  O  OSUs=::  a  S::  d  O  U S:X  a  SU::  d   eSR                  [        [        SU -  U-   5      /S U 5       5      5      nS[        [	        U5      5      -   U-   $ )Nr   r*   '   r   (   c              3   8   #    U  H  n[        U5      v   M     g 7f)N)encode_number).0ps     r   	<genexpr>encode_oid.<locals>.<genexpr>   s     .v!]1vs      )joinr   rK   r   r   )firstsecondpiecesbodys       r   
encode_oidrV      sx    >>a6/R/5A:!v+MM882:./0.v.	
D ]3t9--44r   c                      [        U  Vs/ s H  n[        U5      PM     sn5      nS[        U5      -   SR                  U 5      -   $ s  snf )Nr+   r   )sumr   r   rQ   )encoded_piecesrM   	total_lens      r   encode_sequencer[      sB    ^4^SV^45I]9--0HHH 5s   Ac                 
   / nU (       a&  UR                  SU S-  S-  5        U S-	  n U (       a  M&  U(       d  UR                  S5        US==   S-  ss'   SR                  U Vs/ s H  n[        U5      PM     sn5      $ s  snf )Nr   r,   r"   r8   r9   r   )insertappendrQ   r   )nb128_digitsds      r   rK   rK      sy    K
1q4x4/0F ! 1OtO88+6+QXa[+6776s   $B c                 $    U =(       a    U S S S:H  $ )Nr   r+   r   )strings    r   is_sequencerd      s    +fRajG++r   c                     [        U S5      nUS-  S:w  a  [        SU-  5      eUS-  n[        U SS  5      u  p4U SU-   SU-   U-    nU SU-   U-   S  nX%U4$ )Nr      r   z5wanted type 'constructed tag' (0xa0-0xbf), got 0x%02xr    r   r	   r   read_length)rc   s0r   lengthllenrU   rests          r   remove_constructedrm      s    		"B
T	dCbH
 	
 t)Cvabz*LF!d(QX./D!d(V#%&Dd?r   c                 f   US;  a  [        S5      eUS:X  a  SnOUS:X  a  SnO
US:X  d   eSnSn[        U S	5      nXC-  U:w  a  [        S
R                  X5      5      eUS-  S	:w  a  [        SR                  U5      5      eUS-  n[	        U SS 5      u  pgU SU-   SU-   U-    nU SU-   U-   S n	XXU	4$ )a  
Removes an IMPLICIT tagged value from ``string`` following :term:`DER`.

:param bytes string: a byte string that can have one or more
  DER elements.
:param str exp_class: the expected tag class of the implicitly
  encoded value. Possible values are: "context-specific", "application",
  and "private".
:return: a tuple with first value being the tag without indicator bits,
  second being the raw bytes of the value and the third one being
  remaining bytes (or an empty string if there are none)
:rtype: tuple(int,bytes,bytes)
)r   r   r   zinvalid `exp_class` valuer   r!   r   r"   r   r#   r   z#wanted class {0}, got 0x{1:02x} tag    z(wanted type primitive, got 0x{0:02x} tagr    r   N)r$   r	   r   formatrh   )
rc   	exp_classr&   tag_maskri   r   rj   rk   rU   rl   s
             r   remove_implicitrs      s     FF455M!		(	(	I%%%	H		"B
)#188G
 	
 
J!6==bA
 	
 t)Cvabz*LF!d(QX./D!d(V#%&Dd?r   c                     U (       d  [        S5      eU S S S:w  a  [        U S5      n[        SU-  5      e[        U SS  5      u  p#U[        U 5      S-
  U-
  :  a  [        S5      eSU-   U-   nU SU-   U XS  4$ )Nz'Empty string does not encode a sequencer   r+   r   z)wanted type 'sequence' (0x30), got 0x%02xz&Length longer than the provided buffer)r   r	   rh   r   )rc   r_   rj   lengthlengthendseqs        r   remove_sequencerw      s    EFFbqzW61%G!KLL&vabz2FFa,..DEE&F!l"V,fWo==r   c                     U S S S:w  a  [        U S5      n[        SU-  5      e[        U SS  5      u  p#U SU-   SU-   U-    nU SU-   U-   S  nXE4$ )Nr   rE   r   z,wanted type 'octetstring' (0x04), got 0x%02xrg   )rc   r_   rj   rk   rU   rl   s         r   remove_octet_stringry      sv    bqzW61%JQNOOvabz*LF!d(QX./D!d(V#%&D:r   c                 .   U (       d  [        S5      eU S S S:w  a  [        U S5      n[        SU-  5      e[        U SS  5      u  p#U SU-   SU-   U-    nU SU-   U-   S  nU(       d  [        S5      e[        U5      U:w  a  [        S5      e/ nU(       a+  [	        U5      u  pUR                  U5        XGS  nU(       a  M+  UR                  S5      nUS:  a  US	-  n	OS
n	US	U	-  -
  n
UR                  SU	5        UR                  SU
5        [        U5      U4$ )Nz1Empty string does not encode an object identifierr   rP   r   z'wanted type 'object' (0x06), got 0x%02xzEmpty object identifierz;Length of object identifier longer than the provided bufferP   rI   r*   )	r   r	   rh   r   read_numberr^   popr]   tuple)rc   r_   rj   ru   rU   rl   numberslln0rR   rS   s              r   remove_objectr      sA   ?
 	
 bqzW61%EIJJ&vabz2F!l"Q%5%>?D!l"V+-.D566
4yFI
 	
 G
D!qCy $ 
QB	Bwb2:FNN1eNN1f>4r   c                    U (       d  [        S5      eU S S S:w  a  [        U S5      n[        SU-  5      e[        U SS  5      u  p#U[        U 5      S-
  U-
  :  a  [        S5      eUS:X  a  [        S5      eU SU-   SU-   U-    nU SU-   U-   S  n[        US5      nUS:  d  [        S	5      eUS:  a$  U(       d  [        US5      nUS:  a  [        S
5      e[	        [
        R                  " U5      S5      U4$ )Nz1Empty string is an invalid encoding of an integerr   r-   r   z(wanted type 'integer' (0x02), got 0x%02xz"Length longer than provided bufferz0-byte long encoding of integerr"   z#Negative integers are not supportedz;Invalid encoding of integer, unnecessary zero padding bytes   )r   r	   rh   r   intr0   hexlify)rc   r_   rj   rk   numberbytesrl   msbsmsbs           r   remove_integerr     s%   ?
 	
 bqzW61%FJKKvabz*LFFa$&&@AA{=>>TAHv$56K!d(V#%&D
a
(C:ABBz# k1-$;%  x,b1477r   c                     SnSn[        U S5      S:X  a  [        S5      e U[        U 5      :  a  [        S5      eUS-  n[        X5      nXS-  -  nUS-  nUS-  (       d   X4$ MF  )Nr   r"   z)Non minimal encoding of OID subidentifierzran out of length bytesr8   r,   r   )r	   r   r   )rc   numberrk   ra   s       r   r|   r|   -  s    FDfa D(GHH 3v; 9::16(d(	4x< r   c                     U S:  d   eU S:  a  [        U 5      $ SU -  R                  5       n[        U5      S-  (       a  SU-   n[        R                  " U5      n[        U5      n[        SU-  5      U-   $ )Nr   r"   r)   r*   r+   )r   r/   r   r0   r1   )lr4   rk   s      r   r   r   @  sq    6M64x{	A
1vz1H1Aq6DD4K 1$$r   c                 r   U (       d  [        S5      e[        U S5      nUS-  (       d  US-  S4$ US-  nU(       d  [        S5      eU[        U 5      S-
  :  a  [        S5      e[        U S5      nU(       a  US:X  a  US:  a  [        S5      e[        [        R
                  " U SSU-    5      S	5      SU-   4$ )
Nz,Empty string can't encode valid length valuer   r"   r,   r   z.Invalid length encoding, length of length is 0z,Length of length longer than provided bufferzNot minimal encoding of lengthr   )r   r	   r   r   r0   r   )rc   r5   rk   r   s       r   rh   rh   L  s    JKK

#C$Jd
Q :DLMMc&kAoJKK

#C$!)d
<==xq1t8 45r:AHDDr   c                 J   U (       d  [        S5      eU[        L a  [        R                  " S[        5        [        U S5      nU SS S:w  a  [        SU-  5      e[        U SS 5      u  p4U(       d  [        S5      eU SU-   SU-   U-    nU SU-   U-   S nU[        La  [        US5      nSUs=::  a  S	::  d  O  [        S
5      eUb  X:w  a  [        S5      eUSS nU(       a9  U(       d  [        S5      e[        US5      nUSU-  S-
  -  (       a  [        S5      eUc  XW4nXV4$ )a  
Remove a BIT STRING object from `string` following :term:`DER`.

The `expect_unused` can be used to specify if the bit string should
have the amount of unused bits decoded or not. If it's an integer, any
read BIT STRING that has number of unused bits different from specified
value will cause UnexpectedDER exception to be raised (this is especially
useful when decoding BIT STRINGS that have DER encoded object in them;
DER encoding is byte oriented, so the unused bits will always equal 0).

If the `expect_unused` is specified as None, the first element returned
will be a tuple, with the first value being the extracted bit string
while the second value will be the decoded number of unused bits.

If the `expect_unused` is unspecified, the decoding of byte with
number of unused bits will not be attempted and the bit string will be
returned as-is, the callee will be required to decode it and verify its
correctness.

Future version of python will require the `expected_unused` parameter
to be specified.

:param string: string of bytes to extract the BIT STRING from
:type string: bytes like object
:param expect_unused: number of bits that should be unused in the BIT
    STRING, or None, to return it to caller
:type expect_unused: int or None

:raises UnexpectedDER: when the encoding does not follow DER.

:return: a tuple with first element being the extracted bit string and
    the second being the remaining bytes in the string (if any); if the
    `expect_unused` is specified as None, the first element of the returned
    tuple will be a tuple itself, with first element being the bit string
    as bytes and the second element being the number of unused bits at the
    end of the byte array as an integer
:rtype: tuple
z(Empty string does not encode a bitstringzALegacy call convention used, expect_unused= needs to be specifiedr   Nr   r:   z#wanted bitstring (0x03), got 0x%02xz(Invalid length of bit string, can't be 0r8   zInvalid encoding of unused bitsz Unexpected number of unused bitsz$Invalid encoding of empty bit stringr9   r*   z#Non zero padding bits in bit string)r   r;   r<   r=   r>   r	   rh   )	rc   expect_unusedr5   rj   rk   rU   rl   r?   rB   s	            r   remove_bitstringr   a  sK   N FGG	

 
#CbqzWACGHHvabz*LFFGG!d(QX./D!d(V#%&DG#a(Fa ABB$)@ BCCABx#$JKK!$+Dq&y1}%#$IJJ >D:r   c                 B   [        U [        5      (       a  U R                  5       n SR                  U R	                  S5       Vs/ s H4  nU(       d  M  UR                  S5      (       a  M$  UR                  5       PM6     sn5      n[        R                  " U5      $ s  snf )Nr      
s   -----)	
isinstancer   r/   rQ   split
startswithstripbase64	b64decode)pemr   ra   s      r   unpemr     s    #y!!jjl YYu%	
% h/ AGGI%	
	A A	
s   BB+Bc           	      R   [         R                  " [        U 5      5      nSU-  R                  5       /nUR	                  [        S[        U5      S5       Vs/ s H  oBXDS-    S-   PM     sn5        UR                  SU-  R                  5       5        SR                  U5      $ s  snf )Nz-----BEGIN %s-----
r   L   r   z-----END %s-----
r   )	r   	b64encoder   r/   extendranger   r^   rQ   )dernameb64linesstarts        r   topemr     s    


<,
-C$t+3356E	LL6;As3x6LM6LUURZ	 5	(6LM 
LL&-557888E? 	Ns   B$)r   )&
__future__r   r0   r   r<   	itertoolsr   sixr   r   _compatr   r	   	Exceptionr   r   r'   r6   objectr;   rC   rF   rV   r[   rK   rd   rm   rs   rw   ry   r   r   r|   r   rh   r   r   r   r   r   r   <module>r      s         # 1	I 	DI4A$ (  ' 6Lr/5I
8,
(V
> B8>&	%E* ,3 GPr   