ó Ü_e[c@`sµdZddlmZmZmZmZddlZddlmZm Z m Z ddl m Z m Z ejdkZdZd „Zed „Zd „Zded „Zd „ZdS(uÈ 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. i(tunicode_literalstdivisiontabsolute_importtprint_functionNi(tbyte_clstchr_clst type_name(tint_from_bytest int_to_bytesiu<Insufficient data - %s bytes requested but only %s availablecC`s,t|tƒs(tdt|ƒƒ‚n|dks@|dkrStd|ƒ‚nt|tƒs{tdt|ƒƒ‚n|dks“|dkr¦td|ƒ‚nt|tƒsÎtdt|ƒƒ‚n|dkrítd |ƒ‚nt|tƒstd t|ƒƒ‚nt||||ƒ|S( u™ 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) u!class_ must be an integer, not %siiu*class_ must be one of 0, 1, 2 or 3, not %su!method must be an integer, not %siumethod must be 0 or 1, not %sutag must be an integer, not %su%tag must be greater than zero, not %su&contents must be a byte string, not %s(t isinstancetintt TypeErrorRt ValueErrorRt _dump_header(tclass_tmethodttagtcontents((s7/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/parser.pytemits cC`svt|tƒs(tdt|ƒƒ‚nt|ƒ}t||ƒ\}}|rr||krrtd||ƒ‚n|S(ul 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 u&contents must be a byte string, not %su4Extra data - %d bytes of trailing data were provided(R RR Rtlent_parseR (Rtstrictt contents_lentinfotconsumed((s7/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/parser.pytparseJs cC`sGt|tƒs(tdt|ƒƒ‚nt|t|ƒƒ\}}|S(uW 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 u&contents must be a byte string, not %s(R RR RRR(RRR((s7/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/parser.pytpeekqsc C`sÑ||dkr-ttd||fƒ‚n|}trIt||ƒn||}|d7}|d@}|dkrßd}xctrÛtr˜t||ƒn||}|d7}|d9}||d@7}|d?dkr|Pq|q|Wntrõt||ƒn||}|d7}|d?dkrB|r1|||d@fS||d@} n4|d@} | r|| 7}|t||| |!dtƒ} |rv|| fSnæ|} |d kr¯| d7} nxU| |krt||| d tƒ\} } | | kr²|| d| !d kr²Pq²q²W|r|| fS| |kr<tt| |fƒ‚n|d ?|d ?d@||||!||| d!d f| fS| |kr›tt| |fƒ‚n|d ?|d ?d@||||!||| !df| fS(u 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. :return: A 2-element tuple: - 0: A tuple of (class_, method, tag, header, content, trailer) - 1: An integer indicating how many bytes were consumed iiiii€iitsignedit lengths_onlytiit(R t_INSUFFICIENT_DATA_MESSAGEt_PY2tordtTrueRtFalseR( t encoded_datatdata_lentpointerRtstartt first_octetRtnumt length_octett contents_endt length_octetstsub_header_end((s7/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/parser.pyR‹sl             !   #        c C`s d}d}||d>O}||d>O}|dkr˜|t|dBƒ7}xa|dkr”|dkridnd}|t||d@Bƒ7}|d?}qKWn|t||Bƒ7}t|ƒ}|dkr×|t|ƒ7}n0t|ƒ}|tdt|ƒBƒ7}||7}|S( uÇ 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 Riiiiii€i(RRR( RRRRtheadertid_numtcontinuation_bittlengtht length_bytes((s7/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/parser.pyR õs$     (i(t__doc__t __future__RRRRtsyst_typesRRRtutilRRt version_infoR RRR#RRRR (((s7/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/parser.pyt s"  1 ' j