
    Ii#                         S r SSKJrJrJrJr  SSKrSSKJrJ	r	J
r
  SSKJrJr  \R                  S:*  rSrS	rS
 rSS jrS rSS jrS rg)z
Functions for parsing and dumping using the ASN.1 DER encoding. Exports the
following items:

 - emit()
 - parse()
 - peek()

Other type classes are defined that help compose the types listed above.
    )unicode_literalsdivisionabsolute_importprint_functionN   )byte_clschr_cls	type_name)int_from_bytesint_to_bytes)   z<Insufficient data - %s bytes requested but only %s available
   c                    [        U [        5      (       d  [        S[        U 5      -  5      eU S:  d  U S:  a  [	        SU -  5      e[        U[        5      (       d  [        S[        U5      -  5      eUS:  d  US:  a  [	        SU-  5      e[        U[        5      (       d  [        S[        U5      -  5      eUS:  a  [	        S	U-  5      e[        U[
        5      (       d  [        S
[        U5      -  5      e[        XX#5      U-   $ )aY  
Constructs a byte string of an ASN.1 DER-encoded value

This is typically not useful. Instead, use one of the standard classes from
asn1crypto.core, or construct a new class with specific fields, and call the
.dump() method.

:param class_:
    An integer ASN.1 class value: 0 (universal), 1 (application),
    2 (context), 3 (private)

:param method:
    An integer ASN.1 method value: 0 (primitive), 1 (constructed)

:param tag:
    An integer ASN.1 tag value

:param contents:
    A byte string of the encoded byte contents

:return:
    A byte string of the ASN.1 DER value (header and contents)
z!class_ must be an integer, not %sr   r   z*class_ must be one of 0, 1, 2 or 3, not %sz!method must be an integer, not %sr   zmethod must be 0 or 1, not %sztag must be an integer, not %sz%tag must be greater than zero, not %s&contents must be a byte string, not %s)
isinstanceint	TypeErrorr
   
ValueErrorr   _dump_header)class_methodtagcontentss       7/venv/lib/python3.13/site-packages/asn1crypto/parser.pyemitr      s    2 fc"";i>OOPPzVaZENOOfc"";i>OOPPzVaZ86ABBc389S>IJJ
Qw@3FGGh))@9XCVVWW6AA    c                     [        U [        5      (       d  [        S[        U 5      -  5      e[	        U 5      n[        X5      u  p4U(       a  XB:w  a  [        SX$-
  -  5      eU$ )a  
Parses a byte string of ASN.1 BER/DER-encoded data.

This is typically not useful. Instead, use one of the standard classes from
asn1crypto.core, or construct a new class with specific fields, and call the
.load() class method.

:param contents:
    A byte string of BER/DER-encoded data

:param strict:
    A boolean indicating if trailing data should be forbidden - if so, a
    ValueError will be raised when trailing data exists

:raises:
    ValueError - when the contents do not contain an ASN.1 header or are truncated in some way
    TypeError - when contents is not a byte string

:return:
    A 6-element tuple:
     - 0: integer class (0 to 3)
     - 1: integer method
     - 2: integer tag
     - 3: byte string header
     - 4: byte string content
     - 5: byte string trailer
r   z4Extra data - %d bytes of trailing data were provided)r   r   r   r
   len_parser   )r   strictcontents_leninfoconsumeds        r   parser$   K   s^    : h))@9XCVVWWx=LH3ND(*OS_SjkllKr   c                     [        U [        5      (       d  [        S[        U 5      -  5      e[	        U [        U 5      5      u  pU$ )a'  
Parses a byte string of ASN.1 BER/DER-encoded data to find the length

This is typically used to look into an encoded value to see how long the
next chunk of ASN.1-encoded data is. Primarily it is useful when a
value is a concatenation of multiple values.

:param contents:
    A byte string of BER/DER-encoded data

:raises:
    ValueError - when the contents do not contain an ASN.1 header or are truncated in some way
    TypeError - when contents is not a byte string

:return:
    An integer with the number of bytes occupied by the ASN.1 value
r   )r   r   r   r
   r   r   )r   r"   r#   s      r   peekr&   r   s>    & h))@9XCVVWWHc(m4NDOr   c           
      2   U[         :  a  [        S5      eUnXS-   :  a  [        [        SX-
  4-  5      e[        (       a  [	        X   5      OX   nUS-  nUS-  nUS-	  S-  nUS:X  a  Sn XS-   :  a  [        [        SX-
  4-  5      e[        (       a  [	        X   5      OX   n	US-  nU	S:X  a  US:X  a  [        S5      eUS-  nXyS	-  -  nU	S
-	  S:X  a  OMn  US:  a  [        S5      eXS-   :  a  [        [        SX-
  4-  5      e[        (       a  [	        X   5      OX   n
US-  nSnU
S
-	  S:X  a  X*S	-  -   nOU
S	-  nU(       a5  XU-   :  a  [        [        XU-
  4-  5      eX--  nU[        XU-
  U SS9-   nOVU(       d  [        S5      eUnXS-   :  d  XUS-    S:w  a(  [        XUSUS-   S9u  pXS-   :  a  M  XUS-    S:w  a  M(  US-  nSnX:  a  [        [        X-
  X-
  4-  5      eU(       a  X,4$ US-	  UUXU XU[        U5      -
   U4U4$ )a  
Parses a byte string into component parts

:param encoded_data:
    A byte string that contains BER-encoded data

:param data_len:
    The integer length of the encoded data

:param pointer:
    The index in the byte string to parse from

:param lengths_only:
    A boolean to cause the call to return a 2-element tuple of the integer
    number of bytes in the header and the integer number of bytes in the
    contents. Internal use only.

:param depth:
    The recursion depth when evaluating indefinite-length encoding.

:return:
    A 2-element tuple:
     - 0: A tuple of (class_, method, tag, header, content, trailer)
     - 1: An integer indicating how many bytes were consumed
z*Indefinite-length recursion limit exceededr         r   T   zNon-minimal tag encoding      r   F)signedz-Indefinite-length element must be constructed   s     )lengths_onlydepth   )
_MAX_DEPTHr   _INSUFFICIENT_DATA_MESSAGE_PY2ordr   r   r   )encoded_datadata_lenpointerr/   r0   startfirst_octetr   constructednumlength_octettrailercontents_endlength_octets_s                  r   r   r      s   6 zEFFEA+3q(:L6MMNN04#l+,,:OKqLG

C!#q(K
byA+% !;q(BT>U!UVV04#l+,,:OCqLGd{sax !;<<3JC9Cax1}  8788A+3q(:L6MMNN153|,-<;PLqLGGqA"45 %s*M11 !;}Y`N`>a!abb$G"^L=AXY`4ajo%ppL  !PQQ"LA--<XY>1Z^i1i"(\`hmnoho"p A--<XY>1Z^i1iAL!G3|7MxOa6bbcc&& 1w'c'l!:;	
 	
 
r   c                 p   SnSnXPS-  -  nXQS-  -  nUS:  aC  SnUS:  a)  [        XbS-  -  5      U-   nU(       d  SnUS-	  nUS:  a  M)  [        US-  5      U-   nOU[        XR-  5      -  n[        U5      nUS::  a  U[        U5      -  nU$ [        U5      nU[        S[        U5      -  5      -  nXH-  nU$ )	a  
Constructs the header bytes for an ASN.1 object

:param class_:
    An integer ASN.1 class value: 0 (universal), 1 (application),
    2 (context), 3 (private)

:param method:
    An integer ASN.1 method value: 0 (primitive), 1 (constructed)

:param tag:
    An integer ASN.1 tag value

:param contents:
    A byte string of the encoded byte contents

:return:
    A byte string of the ASN.1 DER header
r   r   r1   r)   r(   r+   r*   r,   )r	   r   r   )	r   r   r   r   headerid_numcont_bitlengthlength_bytess	            r   r   r      s    * FF
kF
kF
byAgXt45>F(C	 Ag
 "%.'&,'']F}'&/! M	 $F+'$\!2233Mr   )F)r   Fr   )__doc__
__future__r   r   r   r   sys_typesr   r	   r
   utilr   r   version_infor4   r3   r2   r   r$   r&   r   r    r   r   <module>rO      sX   	 S R 
 0 0 .
4[ 
.Bb$N4gT.r   