9(Zc@`s6dZddlmZmZmZmZddlmZmZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZddlmZdd lmZmZmZmZmZdd lmZmZdd lmZmZmZm Z e j!d fkr;dd l"m#Z$e%Z&e'Z(nddl)m$Z$e*Z(ej+idd6dd6dd6dd 6Z,idd6dd6dd6d d6dd6dd6dd6d d 6Z-idd6dd6Z.e j/dZ0iZ1e*dZ2de3fdYZ4dfdYZ5de3fdYZ6de3fdYZ7d e4fd!YZ8e8Z9d"e4fd#YZ:d$e4fd%YZ;d&e3fd'YZ<d(e4fd)YZ=d*e7e=fd+YZ>d,e=fd-YZ?d.e=e5fd/YZ@d0e7e6e=e5e3fd1YZAd2e7e6e=fd3YZBd4e7e6e=fd5YZCd6e7e6e=fd7YZDd8e7e6e=fd9YZEd:e7e6e=fd;YZFd<eFfd=YZGd>e=fd?YZHd@e=e5fdAYZIdBe=fdCYZJdDe=fdEYZKdFe=fdGYZLdHe@fdIYZMdJe>fdKYZNdLeIfdMYZOdNe4fdOYZPdPe4fdQYZQdRePfdSYZRdTeQfdUYZSdVePfdWYZTdXe>fdYYZUdZe>fd[YZVd\e>fd]YZWd^eDfd_YZXd`e>fdaYZYdbe>fdcYZZddeZfdeYZ[dfeZfdgYZ\dhe>fdiYZ]dje>fdkYZ^dle>fdmYZ_dne>fdoYZ`dpe>fdqYZadre>fdsYZbdtZcduZddvZedwZfie?d6e@d6eAd 6eDdx6eHdy6eIdz6eJd{6eKd|6eLd}6eMd~6eTd6eNd6eOd6ePd6eRd6eUd6eVd6eWd6eXd6eYd6e[d6e\d6e]d6e^d6e_d6e`d6ead6ebd6ZgehehehdZidehehe*dZjdS(u ASN.1 type classes for universal types. Exports the following items: - load() - Any() - Asn1Value() - BitString() - BMPString() - Boolean() - CharacterString() - Choice() - EmbeddedPdv() - Enumerated() - GeneralizedTime() - GeneralString() - GraphicString() - IA5String() - InstanceOf() - Integer() - IntegerBitString() - IntegerOctetString() - Null() - NumericString() - ObjectDescriptor() - ObjectIdentifier() - OctetBitString() - OctetString() - PrintableString() - Real() - RelativeOid() - Sequence() - SequenceOf() - Set() - SetOf() - TeletexString() - UniversalString() - UTCTime() - UTF8String() - VideotexString() - VisibleString() - VOID - Void() Other type classes are defined that help compose the types listed above. i(tunicode_literalstdivisiontabsolute_importtprint_function(tdatetimet timedeltaNi(t_teletex_codec(tunwrap(t OrderedDict(t type_nametstr_clstbyte_clst int_typestchr_cls(t_parset _dump_header(t int_to_bytestint_from_bytesttimezonetextended_datetimei(tStringIO(tBytesIOu universalu applicationucontextiuprivateu primitiveu constructedu ^\d+(\.\d+)*$cC`stj|d|S(u5 Loads a BER/DER-encoded byte string and construct a universal object based on the tag value: - 1: Boolean - 2: Integer - 3: BitString - 4: OctetString - 5: Null - 6: ObjectIdentifier - 7: ObjectDescriptor - 8: InstanceOf - 9: Real - 10: Enumerated - 11: EmbeddedPdv - 12: UTF8String - 13: RelativeOid - 16: Sequence, - 17: Set - 18: NumericString - 19: PrintableString - 20: TeletexString - 21: VideotexString - 22: IA5String - 23: UTCTime - 24: GeneralizedTime - 25: GraphicString - 26: VisibleString - 27: GeneralString - 28: UniversalString - 29: CharacterString - 30: BMPString :param encoded_data: A byte string of BER or 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 strict is True and trailing data is present ValueError - when the encoded value tag a tag other than listed above ValueError - when the ASN.1 header length is longer than the data TypeError - when encoded_data is not a byte string :return: An instance of the one of the universal classes tstrict(t Asn1Valuetload(t encoded_dataR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRrs3Rc B`seZdZdZdZdZdZeZ dZ dZ dZ dZ dZeedZddeddddddd ZdZdZdZdZdZd Zd Zd Zdd Zd ZdZddZedZRS(u' The basis of all ASN.1 values tcK`snt|ts(tdt|nd}|jdk rF|}nt|d|d|d|\}}|S(u Loads a BER/DER-encoded byte string using the current class as the spec :param encoded_data: A byte string of BER or 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 :return: An instance of the current class u*encoded_data must be a byte string, not %stspect spec_paramsRN(t isinstanceR t TypeErrorR tNonettagt _parse_build(tclsRRtkwargsRtvaluet_((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRs $c C`sy5|jtkr{|j} | jdk rRt| jdtrR| jf| _nt| drn|jntt| u <%s %s %s>N(R>R tidR-tdump(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt__repr__s)cC`s|jjdS(u A fall-back method for print() in Python 2 :return: A byte string of the output of repr() uutf-8(RDtencode(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR?scC`s |jS(u A fall-back method for print() in Python 3 :return: A unicode string of the output of repr() (RD(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR@scC`s@|j}|j|_|j|_|j|_|j|_|S(u Constructs a new copy of the current object, preserving any tagging :return: An Asn1Value object (R&R1R R2R((R6tnew_obj((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt _new_instances      cC`s#|j}|j|tj|S(u Implements the copy.copy() interface :return: A new shallow copy of the current Asn1Value object (RGt_copytcopy(R6RF((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt__copy__s cC`s3|j}||t|<|j|tj|S(u Implements the copy.deepcopy() interface :param memo: A dict for memoization :return: A new deep copy of the current Asn1Value object (RGRBRHRItdeepcopy(R6tmemoRF((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt __deepcopy__s cC`s tj|S(u} Copies the object, preserving any special tagging from it :return: An Asn1Value object (RIRK(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRIscC`s`t|tsi||6}n|jd|jdd|jd}|j|tj|S(u} Copies the object, applying a new tagging to it :param tagging: A dict containing the keys "explicit" and "implicit". Legacy API allows a unicode string of "implicit" or "explicit". :param tag: A integer tag number. Only used when tagging is a unicode string. :return: An Asn1Value object R(uexplicitR2uimplicit(RtdictR&tgetRHRIRK(R6ttaggingR RF((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pytretags *cC`s#|j}|j|tj|S(u{ Copies the object, removing any special tagging from it :return: An Asn1Value object (R&RHRIRK(R6RF((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pytuntags cC`s[|j|jkr9ttdt|t|n|j|_||j|_dS(u! Copies the contents of another Asn1Value object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects uQ Can not copy values from %s object to %s object N(R&RRR R3t_native(R6tothert copy_func((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRH"s   icC`sd|}t|d}t|||rC|jj|dnut|dri|jj|dnOtrt|jtrt d|t |jfnt d||jfdS(uJ Show the binary data and parsed data in a tree structure u uparsediuchosenu%s Native: b%su%s Native: %sN( R)t _basic_debugtparsedtdebugtchosenR>RtnativeR tprintR-(R6t nest_leveltprefixt has_parsed((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRX:s   cC`s|j}|jdks|rt|trB|jrBd|_nt|j|j|j |j}|j dk rx:|j D],\}}t|d|||j|}q|Wn||_d|_ n|j|S(u Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value iiRN( R3t_headerRRt Constructablet _indefinitetmethodRR1R R(t_trailer(R6tforceR3theaderR1R ((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRCPs  !'  N(t__name__t __module__t__doc__RRbR1R t_bad_tagtFalseR2R(R_R3RcRSt classmethodRR=RARDR?R@RGRJRMRIRQRRRHRXRC(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRs8      tValueMapcB`s#eZdZdZdZdZRS(ul Basic functionality that allows for mapping values from ints or OIDs to python unicode strings cC`se|j}|jdks'|jdk r+dSi|_x*|jjD]\}}||j|R?R@(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRAOs  cC`s |jS(u; A byte string of the DER-encoded contents (RC(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR?]scC`s t|S(u7 :return: A unicode string (R-(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR@dscC`s)dt|t|t|jfS(u7 :return: A unicode string u <%s %s %s>(R RBR-RC(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRDlscC`s#|j}|j|tj|S(u| Implements the copy.copy() interface :return: A new shallow copy of the Concat object (R&RHRI(R6RF((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRJts cC`s3|j}||t|<|j|tj|S(u Implements the copy.deepcopy() interface :param memo: A dict for memoization :return: A new deep copy of the Concat object and all child objects (R&RBRHRIRK(R6RLRF((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRMs cC`s tj|S(uQ Copies the object :return: A Concat object (RIRK(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRIscC`sO|j|jkr9ttdt|t|n||j|_dS(u Copies the contents of another Concat object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects uQ Can not copy values from %s object to %s object N(R&RRR R(R6RTRU((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRHs  icC`sgd|}td|t|t|ftd|fx"|jD]}|j|dqHWdS(uJ Show the binary data and parsed data in a tree structure u u%s%s Object #%su %s Children:iN(R[R RBRRX(R6R\R]tchild((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRXs  #cC`s4d}x'|jD]}||jd|7}qW|S(u Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value RRd(RRC(R6RdR3R((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRCs cC`s |jS(u` :return: A byte string of the DER-encoded contents of the children (RC(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR3scC`s t|jS(u. :return: Integer (R.R(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRscC`sQ|t|jdks%|dkrFttd|t|n|j|S(u Allows accessing children by index :param key: An integer of the child index :raises: KeyError - when an index is invalid :return: The Asn1Value object of the child specified iiuN No child is definition for position %d of %s (R.RtKeyErrorRR R(R6Rp((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt __getitem__s %cC`s|t|jdks%|dkrFttd|t|nt|tsvttd|t|n||j|eZdZdZdZdZdZedZRS(u7 Represents a boolean in both ASN.1 and Python icC`sLt||_|sdnd|_d|_|jdkrHd|_ndS(u Sets the value of the object :param value: True, False or another value that works with bool() tsRN(tboolRSR3RR_Rc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4s  cC`s |jS(u4 :return: True or False (t__bool__(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR~scC`s |jdkS(u4 :return: True or False R(R3(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR scC`s;|jdkrdS|jdkr4|j|_n|jS(u} The a native Python datatype representation of this value :return: True, False or None N(R3RRSR(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZs ( RfRgRhR R4R~RRRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRs    tIntegercB`s5eZdZdZdZdZedZRS(u8 Represents an integer in both ASN.1 and Python icC`st|tr||jdkr<ttdt|n||jkrlttdt||n|j|}n6t|tst tdt|t|n|jr||jkr|j|n||_ t |dt |_ d|_|jdkrd|_ndS(u Sets the value of the object :param value: An integer, or a unicode string if _map is set :raises: ValueError - when an invalid value is passed u\ %s value is a unicode string, but no _map provided uR %s value, %s, is not present in the _map u %s value must be an integer or unicode string when a name_map is provided, not %s tsignedRN(RR RmRR,RR RnR RRSRR+R3R_Rc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4,s*   . cC`st|jdtS(u1 :return: An integer R(RR3R+(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt__int__\scC`sr|jdkrdS|jdkrk|j|_|jdk rk|j|jkrk|j|j|_qkn|jS(u| The a native Python datatype representation of this value :return: An integer or None N(R3RRSRRm(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZcs !(RfRgRhR R4RRRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR%s  0 t BitStringcB`sbeZdZdZd Zd ZdZdZdZ dZ dZ dZ e dZRS( uK Represents a bit string from ASN.1 as a Python tuple of 1s and 0s iicC`sHtj||j}|jdk rDt|jjd|_ndS(u2 Generates _reverse_map from _map iN(RlR*R&RmRtmaxtkeyst_size(R6R"((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR*s  c C`st|tr|jd kr<ttdt|ndg|j}||_xWt d|jD]C}|jj |}|d krqhn||krhd|| Represents a bit string in ASN.1 as a Python integer iicC`st|ts6ttdt|t|n||_dt|dt|_d|_ |j rt |_ d|_ n|jdkrd|_ndS(u Sets the value of the object :param value: An integer :raises: ValueError - when an invalid value is passed uE %s value must be an integer, not %s RRiRN(RR RRR RSRR+R3RR_RaRjRbRc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4s       cC`st|jdd!}djt|jd}t|d}|dkrcdd||}n|dkr~|dd|!S|S(u Allows reconstructing indefinite length values :return: A unicode string of bits - 1s and 0s iiu{0:b}iu0(RR3RR.(R6RRR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRt s  cC`s|jdkrdS|jdkrt|jdd!}|j rg|dkrgt|jd|_q|jr|dkrtdnt|jd|_n|jS(u| The a native Python datatype representation of this value :return: An integer or None iiu=Constructed bit string has extra bits on indefinite containeriN(R3RRSRRaR,RRv(R6R((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZ* s ( RfRgRhR RuR4RtRRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRs   t OctetStringcB`sDeZdZdZdZdZdZdZe dZ RS(u; Represents a byte string in both ASN.1 and Python icC`st|ts6ttdt|t|n||_||_d|_|j rot |_ d|_ n|j dkrd|_ ndS(u_ Sets the value of the object :param value: A byte string uH %s value must be a byte string, not %s iRN( RR RRR RR3RR_RaRjRbRc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4L s       cC`s;|jdkrdS|jdkr4|j|_n|jS(u4 :return: A byte string RN(R3RRRv(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR?f s cC`s)tt|j|||j|_dS(u# Copies the contents of another OctetString object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects N(R{RRHR(R6RTRU((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRHr s cC`s|jdkrdS|jS(u The a native Python datatype representation of this value :return: A byte string or None N(R3RR?(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZ s N( RfRgRhR RRR4R?RHRRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRB s  tIntegerOctetStringcB`s,eZdZdZdZedZRS(u? Represents a byte string in ASN.1 as a Python integer icC`st|ts6ttdt|t|n||_t|dt|_d|_ |j r{t|_ d|_ n|j dkrd|_ ndS(u Sets the value of the object :param value: An integer :raises: ValueError - when an invalid value is passed uE %s value must be an integer, not %s RiRN(RR RRR RSRRjR3RR_RaRbRc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4 s       cC`sA|jdkrdS|jdkr:t|j|_n|jS(u| The a native Python datatype representation of this value :return: An integer or None N(R3RRSRRv(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZ s (RfRgRhR R4RRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR s tParsableOctetStringcB`s}eZdZd Zd Zd d dZdZd d dZdZ dZ e dZ e dZ edZRS( icK`szt}|dkrB|dk rBt|trB|j}t}ntj|d|||rv||jdf|_ ndS(u Allows providing a parsed object that will be serialized to get the byte string value :param value: A native Python datatype to initialize the object value with :param parsed: If value is None and this is an Asn1Value object, this will be set as the parsed value, and the value will be obtained by calling .dump() on this object. R$N( RjRRRRCR+RR=R&R(R6R$RWR#t set_parsed((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR= s'  cC`st|ts6ttdt|t|n||_||_d|_|j rot |_ d|_ n|j dkrd|_ ndS(u_ Sets the value of the object :param value: A byte string uH %s value must be a byte string, not %s iRN( RR RRR RR3RR_RaRjRbRc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4 s       cC`so|jdks+|jdd!||fkrdt|jd|d|\}}|||f|_n|jdS(uv Parses the contents generically, or using a spec with optional params :param spec: A class derived from Asn1Value that defines what class_ and tag the value should have, and the semantics of the encoded value. The return value will be of this type. If omitted, the encoded value will be decoded using the standard universal tag based on the encoded tag number. :param spec_params: A dict of params to pass to the spec object :return: An object of the type spec, or if not present, a child of Asn1Value iiRRiN(RRR!R?(R6RRRR%((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR s+$cC`s;|jdkrdS|jdkr4|j|_n|jS(u4 :return: A byte string RN(R3RRRv(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR? s cC`s;tt|j|||j|_||j|_dS(u+ Copies the contents of another ParsableOctetString object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects N(R{RRHRR(R6RTRU((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRH# s  cC`s>|jdkrdS|jdk r0|jdjS|jSdS(u The a native Python datatype representation of this value :return: A byte string or None iN(R3RRRZR?(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZ3 s cC`s'|jdkr|jn|jdS(uw Returns the parsed object from .parse() :return: The object returned by .parse() iN(RRR(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRWD s  cC`s\|rO|jdk r-|jjd|}n |j}d|_|j|ntj|S(u Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value RdN(RRRWRCRZR3R4R(R6RdRZ((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRCR s   N(RfRgR RRRR=R4RR?RHRRZRWRjRC(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR s  tParsableOctetBitStringcB`seZdZdZdZRS(iicC`st|ts6ttdt|t|n||_d||_d|_|j rst |_ d|_ n|j dkrd|_ ndS(u Sets the value of the object :param value: A byte string :raises: ValueError - when an invalid value is passed uH %s value must be a byte string, not %s RiRN( RR RRR RR3RR_RaRjRbRc(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4s s        (RfRgR RuR4(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRi stNullcB`s2eZdZdZdZdZedZRS(u< Represents a null value in ASN.1 as None in Python iRcC`s d|_dS(uV Sets the value of the object :param value: None RN(R3(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4 scC`sdS(un The a native Python datatype representation of this value :return: None N(R(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZ s (RfRgRhR R3R4RRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR s  tObjectIdentifiercB`sheZdZdZdZedZedZdZ dZ e dZ e dZ RS( u` Represents an object identifier in ASN.1 as a Python unicode dotted integer string icC`sm|jdkr-ttdt|nt|tsZttdt|n|jj||S(u^ Converts a dotted unicode string OID into a mapped unicode string :param value: A dotted unicode string OID :raises: ValueError - when no _map dict has been defined on the class TypeError - when value is not a unicode string :return: A mapped unicode string u> %s._map has not been defined uH value must be a unicode string, not %s N( RmRR,RR RR RRO(R"R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR scC`s|tkr&|jtt| %s._map has not been defined uH value must be a unicode string, not %s uL %s._map does not contain an entry for "%s" N(R'R*R+RmRR,RR RR RRnt_OID_REtmatch(R"R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pytunmap s&     cC`slt|ts6ttdt|t|n||_|jd k rp||jkrp|j|}qpnd|_ d }xt |j dD]\}}t |}|dkr|}qn|dkr|d|}nt d|@}|d?}x2|dkr0t d d|@B|}|d?}qW|j |7_ qWd |_|jdkrhd|_nd S( u  Sets the value of the object :param value: A unicode string. May be a dotted integer string, or if _map is provided, one of the mapped values. :raises: ValueError - when an invalid value is passed uK %s value must be a unicode string, not %s Ru.iii(iiiN(RR RRR RSRmRRnR3RtsplitRR R_Rc(R6R$tfirstRtpartt encoded_part((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4 s6    "     cC`s|jS(u7 :return: A unicode string (tdotted(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR@B scC`s|jdkrg}d}x|jD]}tr@t|}n|d}||d@7}|d@dkr%t|dkr|jt|d|jt|dn|jt|d}q%q%Wdj||_n|jS(u :return: A unicode string of the object identifier in dotted notation, thus ignoring any mapped value iiii(u.N( t_dottedRR3R>tordR.RR R(R6RyRtbyte((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRJ s   cC`so|jdkrdS|jdkrh|j|_|jdk rh|j|jkrh|j|j|_qhn|jS(uE The a native Python datatype representation of this value :return: A unicode string or None. If _map is not defined, the unicode string is a string of dotted integers. If _map is defined and the dotted string is present in the _map, the mapped value is returned. N(R3RRSRRm(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZg s  !N(RfRgRhR RRRkRRR4R@RRRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR s"2 2 tObjectDescriptorcB`seZdZdZRS(uO Represents an object descriptor from ASN.1 - no Python implementation i(RfRgRhR (((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR| st InstanceOfcB`seZdZdZRS(uF Represents an instance from ASN.1 - no Python implementation i(RfRgRhR (((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR stRealcB`seZdZdZRS(uH Represents a real number from ASN.1 - no Python implementation i (RfRgRhR (((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR st EnumeratedcB`s,eZdZdZdZedZRS(u\ Represents a enumerated list of integers from ASN.1 as a Python unicode string i cC`st|t rGt|t rGttdt|t|nt|tr||jkrttdt||n|j|}n0||jkrttdt||nt j ||dS(u Sets the value of the object :param value: An integer or a unicode string from _map :raises: ValueError - when an invalid value is passed uY %s value must be an integer or a unicode string, not %s uL %s value "%s" is not a valid value uB %s value %s is not a valid value N( RR R RRR RnR,RmRR4(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4 s$    cC`sB|jdkrdS|jdkr;|j|j|_n|jS(u The a native Python datatype representation of this value :return: A unicode string or None N(R3RRSRmR(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZ s (RfRgRhR R4RRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR s +t UTF8StringcB`seZdZdZdZRS(uI Represents a UTF-8 string from ASN.1 as a Python unicode string i uutf-8(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR st RelativeOidcB`seZdZdZRS(u` Represents an object identifier in ASN.1 as a Python unicode dotted integer string i (RfRgRhR (((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR stSequencecB`s=eZdZdZdZdZdZdZe Z gZ dZ dZ dZdZdZdZdZdddZedZejdZdZdZd Zd Zd Zd Zd Ze dZdZdZ dZ!e dZ"dZ#edZ$dZ%ddZ&e dZ'RS(uf Represents a sequence of fields from ASN.1 as a Python object with a dict-like interface iiic K`stj||t}|dkrq|dk rqt}|jdkrh|jdkr[t}qh|jn|}n|dk ry=|jrg|jD]}|d^q}t |j }n|j }t |}x|D]}|rC|j |} | t |jkrC|j| t k rC||kr|j|qqqCn||kr|j||||j|qqWt |rttdt|djtt|nWqttfk r } | jd} | jddt|f| | _| qXndS(u" Allows setting field values before passing everything else along to Asn1Value.__init__() :param value: A native Python datatype to initialize the object value with :param default: The default value if no value is specified iu One or more unknown fields was passed to the constructor of %s: %s u, iu while constructing %sN(RR=RjRR+tchildrenR3t_parse_childrent_fieldsR4Rt _field_mapR.tVOIDRRR,RR RtsortedRRR5( R6R$R:R#tcheck_existingRRt unused_keysRpRR<R5((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR=# sF           (     ( %cC`s6|jdkr|jS|jr/|jn|jS(u` :return: A byte string of the DER-encoded contents of the sequence N(RRt _contentst _is_mutatedt _set_contents(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR3d s   cC`s ||_dS(ue :param value: A byte string of the DER-encoded contents of the sequence N(R(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR3s scC`sf|j}|jdk rbxG|jD]9}t|tsFt|tr"|pU|j}q"q"Wn|S(u~ :return: A boolean - if the sequence or any children (recursively) have been mutated N(t_mutatedRRRRt SequenceOfR(R6tmutatedR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR| s  cC`s:|j|}|jtkr6t|}|j|         c C`sy|j}|jdkr|jrtgt|j|_xt|jD]\}\}}}d|krJ|j|r|j|\}}}} }n|j |\}}}} }|j |||| d|j|}|jtkrc|jj|q;|jj|jq;WndS(u  Copies the contents of another Sequence object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects N( R{RRHRRR&RRRI(R6RTRUR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRHs  cC`s|jdkr|jnd|}t||xX|D]P}|j|j|}|tk r:td||f|j|dq:q:WdS(uJ Show the binary data and parsed data in a tree structure u u%s Field "%s"iN( RRRRVRRRR[RX(R6R\R]R R((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRXs     cC`s|r|jd|n|jr|jdk rxut|jD]a\}\}}}|j|tk roqAnd|ksAd|krqAnttd|qAWntj |S(u Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value RdudefaultuoptionaluN Field "%s" is missing from structure N( RRRRRRR,RRRC(R6RdRR R%R((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRCs %N((RfRgRhR R1RbRRRRjRRRRRRRRRR=RR3tsetterRRRRRRRRR*RRRRRZRHRXRC(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR sF A  . 9 - %  / I '!  RcB`seZdZdZdZdZdZdZe Z dZ dddddZ e dZejdZdZdZd Zd Zd Zd Zd ZdZdZdZe dZe dZdZe dZdZddZe dZ RS(u Represents a sequence (ordered) of a single type of values from ASN.1 as a Python object with a list-like interface iiic K`s|r||_ntj||y|dk r=||_ny|dkr^|dk r^|}n|dk rx*t|D]\}}|j||qwW|jdkr|jqnWnQtt fk r }|j d} |j ddt |f| |_ |nXdS(u Allows setting child objects and the _child_spec via the spec parameter before passing everything else along to Asn1Value.__init__() :param value: A native Python datatype to initialize the object value with :param default: The default value if no value is specified :param contents: A byte string of the encoded contents of the value :param spec: A class derived from Asn1Value to use to parse children iiu while constructing %sN( t _child_specRR=RR3RRRR,RR5R ( R6R$R:R3RR#RRR<R5((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR= s"      %cC`s6|jdkr|jS|jr/|jn|jS(u` :return: A byte string of the DER-encoded contents of the sequence N(RRRRR(R6((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR3Ks   cC`s ||_dS(ue :param value: A byte string of the DER-encoded contents of the sequence N(R(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR3ZscC`sf|j}|jdk rbxG|jD]9}t|tsFt|tr"|pU|j}q"q"Wn|S(u~ :return: A boolean - if the sequence or any children (recursively) have been mutated N(RRRRRRR(R6RR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRcs  cC`s<|j|}|jtkr8t|}||j|}|jtkrc|jj|q;|jj|jq;WndS(u" Copies the contents of another SequenceOf object to itself :param object: Another instance of the same class :param copy_func: An reference of copy.copy() or copy.deepcopy() to use when copying lists, dicts and objects N( R{RRHRRR&RRRI(R6RTRUR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRHs  cC`sY|jdkr|jnd|}t||x|D]}|j|dq:WdS(uJ Show the binary data and parsed data in a tree structure u iN(RRRRVRX(R6R\R]R((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRXs     cC`s&|r|jd|ntj|S(u Encodes the value using DER :param force: If the encoded contents already exist, clear them and regenerate to ensure they are in DER format instead of BER format :return: A byte string of the DER-encoded value Rd(RRRC(R6Rd((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRCs N(!RfRgRhR R1RbRRRRjRR4R=RR3R3RRRRRRRRR7RRRRRZRHRXRC(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRs8+  7       #   tSetcB`sGeZdZdZdZdZdZdZe dZ e dZ RS(um Represents a set of fields (unordered) from ASN.1 as a Python object with a dict-like interface iiicC`s|j}i|_i|_g|_x{t|jD]j\}}t|dkro|if}||j||j}|jdkr|jrtgt|j|_xt|jD]\}\}}}d|krJ|j|r|j|\}}}} }n|j |\}}}} }|j |||| d|j||sRiN( RRRRRCRRR tsortRRR_Rc( R6Rdtchild_tag_encodingsRRtchild_encodingRRR R=((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRbs    ) N( RfRgRhRbR1R RRR*RjRR(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR8s  otSetOfcB`s eZdZdZedZRS(u~ Represents a set (unordered) of a single type of values from ASN.1 as a Python object with a list-like interface icC`s|jdkr|jng}x'|D]}|j|jd|q)Wdjt||_d|_|j dkrd|_ ndS(uD Encodes all child objects into the contents for this object. This method is overridden because a SetOf needs to be encoded by sorting the child encodings. :param force: Ensure all contents are in DER format instead of possibly using cached BER-encoded data RdRN( RRRRRCRRRR_Rc(R6Rdtchild_encodingsR((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRs    (RfRgRhR RjR(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRBst EmbeddedPdvcB`seZdZdZRS(u A sequence structure i (RfRgRhR (((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRDst NumericStringcB`seZdZdZdZRS(uK Represents a numeric string from ASN.1 as a Python unicode string iulatin1(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyREstPrintableStringcB`seZdZdZdZRS(uM Represents a printable string from ASN.1 as a Python unicode string iulatin1(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRFst TeletexStringcB`seZdZdZdZRS(uK Represents a teletex string from ASN.1 as a Python unicode string iuteletex(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRGstVideotexStringcB`seZdZdZRS(uI Represents a videotex string from ASN.1 as a Python byte string i(RfRgRhR (((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRHst IA5StringcB`seZdZdZdZRS(uH Represents an IA5 string from ASN.1 as a Python unicode string iuascii(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRIst AbstractTimecB`seZdZedZRS(uK Represents a time from ASN.1 as a Python datetime.datetime object cC`s|jd krd S|jd krt|}tjd|}|s|jd}|j|}|jdt j |_q|j|dd!}t |dd!}t |d}t dt |d |}|dkr||8}n ||7}|jdt j |_n|jS( u The a native Python datatype representation of this value :return: A datetime.datetime object in the UTC timezone or None u[-\+]uZttzinfoiiiithourstminutesN(R3RRSR tretsearchRt _date_by_lentreplaceRtutcRRtabs(R6tstringt has_timezonetdateRLRMtdelta((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRZs$     (RfRgRhRRZ(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRJstUTCTimecB`s&eZdZdZdZdZRS(uV Represents a UTC time from ASN.1 as a Python datetime.datetime object in UTC icC`sVt|tr9|jd}tr9|jd}q9ntj||d|_dS(u Sets the value of the object :param value: A unicode string or a datetime.datetime object :raises: ValueError - when an invalid value is passed u %y%m%d%H%M%SZuasciiN( RRtstrftimeR>RRR4RRS(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4s cC`s~t|}t|dd!}|dkr4d}nd}|dkrZtj||dS|dkrztj||d S|S( u Parses a date from a string based on its length :param string: A unicode string to parse :return: A datetime.datetime object or a unicode string iii2u20u19i u %Y%m%d%H%Mi u %Y%m%d%H%M%S(R.RRtstrptime(R6RTtstrlentyear_numR]((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRP#s     (RfRgRhR R4RP(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRXs tGeneralizedTimecB`s&eZdZdZdZdZRS(u Represents a generalized time from ASN.1 as a Python datetime.datetime object or asn1crypto.util.extended_datetime object in UTC icC`s\t|ttfr?|jd}tr?|jd}q?ntj||d|_ dS(u Sets the value of the object :param value: A unicode string, a datetime.datetime object or an asn1crypto.util.extended_datetime object :raises: ValueError - when an invalid value is passed u %Y%m%d%H%M%SZuasciiN( RRRRYR>RRR4RRS(R6R$((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR4Gs c C`st|}d }|dkr'd}n?|dkr<d}n*|dkrQd}n|dkrfd}n|rt|d kr|d d !d krtjd |d |}td |j|j|j|j|j |j |j Stj||S|S(u Parses a date from a string based on its length :param string: A unicode string to parse :return: A datetime.datetime object, asn1crypto.util.extended_datetime object or a unicode string i u%Y%m%d%Hi u %Y%m%d%H%Miu %Y%m%d%H%M%Siu%Y%m%d%H%M%S.%fiiu0000u2000N( R.RRRZRtmonthtdaythourtminutetsecondt microsecondRK(R6RTR[t date_formattt((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRP]s0         % (RfRgRhR R4RP(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyR]?s t GraphicStringcB`seZdZdZdZRS(uK Represents a graphic string from ASN.1 as a Python unicode string iulatin1(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRfst VisibleStringcB`seZdZdZdZRS(uK Represents a visible string from ASN.1 as a Python unicode string iulatin1(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRgst GeneralStringcB`seZdZdZdZRS(uK Represents a general string from ASN.1 as a Python unicode string iulatin1(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRhstUniversalStringcB`seZdZdZdZRS(uM Represents a universal string from ASN.1 as a Python unicode string iu utf-32-be(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRistCharacterStringcB`seZdZdZdZRS(uM Represents a character string from ASN.1 as a Python unicode string iulatin1(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRjst BMPStringcB`seZdZdZdZRS(uG Represents a BMP string from ASN.1 as a Python unicode string iu utf-16-be(RfRgRhR R(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRkscC`std|t|t|f|jr^td|tj|jpGdjdfn|jd k o|j d k o|j d k }|rt j |j}t j |j }n|jd k r*x7|jD],\}}td|t j ||fqW|rtd||||j fqnX|jr\|rtd||||j fqn&|rtd||||j fntd |tj|jpdjdfd S( u7 Prints out basic information about an Asn1Value object. Extracted for reuse among different classes that customize the debug information. :param prefix: A unicode string of spaces to prefix output line with :param self: The object to print the debugging information about u%s%s Object #%su%s Header: 0x%sRuutf-8u#%s %s tag %s (explicitly tagged)u%s %s %s %su&%s %s %s tag %s (implicitly tagged)u%s %s %s tag %su%s Data: 0x%sN(R[R RBR_tbinasciithexlifyRRbRR1R R%ROR/R(R2R3(R]R6t has_headert method_namet class_nameR1R ((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyRVs, # 2- # # cC`sd|kr|ddkr?|jdd|df|dtioRjtregisterR/R0R%tcompileRR'RtobjectRRlRqR`R|RRRRRRRRRRRRRRRRRRRRRRRRRR8RBRDRERFRGRHRIRJRXR]RfRgRhRiRjRkRVRRRRuRRR!(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/core.pyt/s"     ("      6,G6 9"{Q5Q"!XTN5)D  !!    .8I      ,  ( -