a bx7@sUddlZddlZddlZddlZddlZddlmZddlmZ ddl m Z m Z Gdddej ZddeDZe jeje jeje jeje jeje jeje jejiZeje efed <eje efZe jd e jd e j d e j!d e j"de jde j#de jde j$di Z%eed<dde%&DZ'ej(ee)fedddZ*eedddZ+GdddZ,GdddZ-GdddZ.Gd d!d!Z/dS)"N)utils)x509)NameOIDObjectIdentifierc@s<eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd S) _ASN1Type N)__name__ __module__ __qualname__ BitStringZ OctetString UTF8StringZ NumericStringPrintableStringZ T61String IA5StringZUTCTimeZGeneralizedTimeZ VisibleStringZUniversalStringZ BMPStringrr=/tmp/pip-target-98j97qn4/lib/python/cryptography/x509/name.pyrsrcCsi|] }|j|qSr)value.0irrr !r _NAMEOID_DEFAULT_TYPEZCNLZSTOZOUCZSTREETZDCUID_NAMEOID_TO_NAMEcCsi|]\}}||qSrr)rkvrrrr ;r!)valreturncCs|sdSt|tr&dt|dS|dd}|dd}|dd }|d d }|d d }|dd}|dd}|dd}|ddvrd|}|ddkr|ddd}|S)z>Escape special characters in RFC4514 Distinguished Name value.#utf8\z\\"z\"+z\+,z\,;z\;z\>z\00r)r- r7Nz\ ) isinstancebytesbinasciihexlifydecodereplace)r*rrr_escape_dn_value>s"           r?cCs|sdSdd}tj||S)Nr,cSs(|d}t|dkr|Stt|dS)N)grouplenchrint)mr*rrrsubcs  z_unescape_dn_value..sub)_RFC4514NameParser_PAIR_RErG)r*rGrrr_unescape_dn_value[srJc@seZdZdddeejeefeje e ddddZ e eddd Z e ejeefdd d Ze edd d ZdejeedddZee dddZedddZedddZdS) NameAttributeNT) _validate)oidr_typerLr+cCst|tstd|tjkrB|tjkr.tdt|tsTtdnt|tsTtd|tj ksh|tj krt|tsvJt | d}|dkr|durt dn|dkrtjd |dd |durt|tj}t|tstd ||_||_||_dS) Nz2oid argument must be an ObjectIdentifier instance.z6oid must be X500_UNIQUE_IDENTIFIER for BitString type.z!value must be bytes for BitStringzvalue argument must be a strr.Tz/Country name must be a 2 character country codezUCountry names should be two characters, but the attribute is {} characters in length.) stacklevelz%_type must be from the _ASN1Type enum)r9r TypeErrorrrrZX500_UNIQUE_IDENTIFIERr:str COUNTRY_NAMEJURISDICTION_COUNTRY_NAMErCencode ValueErrorwarningswarnformatr"getr_oid_valuerN)selfrMrrNrLZc_lenrrr__init__osJ        zNameAttribute.__init__r+cCs|jSN)r[r]rrrrMszNameAttribute.oidcCs|jSr`)r\rarrrrszNameAttribute.valuecCst|j|jjS)zt The short attribute name (for example "CN") if available, otherwise the OID dotted string. )r'rZrMZ dotted_stringrarrrrfc4514_attribute_namesz$NameAttribute.rfc4514_attribute_nameattr_name_overridesr+cCs6|r||jnd}|dur"|j}|dt|jS)z Format as RFC4514 Distinguished Name string. Use short attribute name if available, otherwise fall back to OID dotted string. N=)rZrMrbr?r)r]rd attr_namerrrrfc4514_strings zNameAttribute.rfc4514_stringotherr+cCs&t|tstS|j|jko$|j|jkSr`)r9rKNotImplementedrMrr]rirrr__eq__s zNameAttribute.__eq__cCst|j|jfSr`)hashrMrrarrr__hash__szNameAttribute.__hash__cCs d|S)Nz/)rYrarrr__repr__szNameAttribute.__repr__)N)N)rrrrtypingUnionrRr:Optionalrboolr^propertyrMrrb _OidNameMaprgobjectrlrErnrorrrrrKns0  8 rKc@seZdZejedddZeejedddZ dej e e dd d Z eed d d ZedddZejedddZedddZe dddZdS)RelativeDistinguishedName) attributescCs\t|}|stdtdd|Ds.td||_t||_t|jt|krXtddS)Nz-a relative distinguished name cannot be emptycss|]}t|tVqdSr`r9rKrxrrr r!z5RelativeDistinguishedName.__init__..z/attributes must be an iterable of NameAttributez$duplicate attributes are not allowed)listrVallrQ _attributes frozenset_attribute_setrCr]rxrrrr^s z"RelativeDistinguishedName.__init__rMr+csfdd|DS)Ncsg|]}|jkr|qSrrMrrrr r!zDRelativeDistinguishedName.get_attributes_for_oid..rr]rMrrrget_attributes_for_oidsz0RelativeDistinguishedName.get_attributes_for_oidNrccsdfdd|jDS)z Format as RFC4514 Distinguished Name string. Within each RDN, attributes are joined by '+', although that is rarely used in certificates. r1c3s|]}|VqdSr`rgrattrrdrrr|sz;RelativeDistinguishedName.rfc4514_string..)joinrr]rdrrrrgs z(RelativeDistinguishedName.rfc4514_stringrhcCst|tstS|j|jkSr`)r9rwrjrrkrrrrls z RelativeDistinguishedName.__eq__r_cCs t|jSr`)rmrrarrrrnsz"RelativeDistinguishedName.__hash__cCs t|jSr`)iterrrarrr__iter__sz"RelativeDistinguishedName.__iter__cCs t|jSr`)rCrrarrr__len__sz!RelativeDistinguishedName.__len__cCsd|S)Nz)rYrgrarrrrosz"RelativeDistinguishedName.__repr__)N)rrrrpIterablerKr^rListrrrrurRrgrvrsrlrErnIteratorrrrorrrrrws  rwc@s eZdZejejeddddZejejeddddZejej eefddddZe e dddd Z d!ej ee d d d Zeejed ddZeejedddZd"ejedddZeedddZedddZejedddZedddZe ddd Z dS)#NameN)rxr+cCsdSr`rrrrrr^ sz Name.__init__cCsdSr`rrrrrr^scCs`t|}tdd|Dr,dd|D|_n0tdd|DrTttjt||_ntddS)Ncss|]}t|tVqdSr`ryrzrrrr|r!z Name.__init__..cSsg|]}ttt|gqSr)rwrpcastrKrzrrrrsz!Name.__init__..css|]}t|tVqdSr`)r9rwrzrrrr|!r!zNattributes must be a list of NameAttribute or a list RelativeDistinguishedName)r}r~rrprrrwrQrrrrr^s  datar+cCs t|Sr`)rHparse)clsrrrrfrom_rfc4514_string+szName.from_rfc4514_stringrccsdfddt|jDS)a Format as RFC4514 Distinguished Name string. For example 'CN=foobar.com,O=Foo Corp,C=US' An X.509 name is a two-level structure: a list of sets of attributes. Each list element is separated by ',' and within each list element, set elements are separated by '+'. The latter is almost never used in real world certificates. According to RFC4514 section 2.1 the RDNSequence must be reversed when converting to string representation. r2c3s|]}|VqdSr`rrrrrr|<sz&Name.rfc4514_string..)rreversedrrrrrrg/s zName.rfc4514_stringrcsfdd|DS)Ncsg|]}|jkr|qSrrrrrrrDr!z/Name.get_attributes_for_oid..rrrrrrAszName.get_attributes_for_oidr_cCs|jSr`rrarrrrdnsFsz Name.rdns)backendr+cCs t|Sr`) rust_x509Zencode_name_bytes)r]rrrr public_bytesJszName.public_bytesrhcCst|tstS|j|jkSr`)r9rrjrrkrrrrlMs z Name.__eq__cCstt|jSr`)rmtuplerrarrrrnSsz Name.__hash__ccs |jD]}|D] }|VqqdSr`r)r]rdnZavarrrrXs z Name.__iter__cCstdd|jDS)Ncss|]}t|VqdSr`)rC)rrrrrr|^r!zName.__len__..)sumrrarrrr]sz Name.__len__cCs ddd|jD}d|S)Nr2css|]}|VqdSr`rrrrrr|ar!z Name.__repr__..z )rrrYr]rrrrro`sz Name.__repr__)N)N)!rrrrpoverloadrrKr^rwrq classmethodrRrrrrurgrrrrtrAnyr:rrvrsrlrErnrrrrorrrrr s:    rc@s.eZdZedZedZdZeeZdZ dZ dZ de e jdZe d eZe d eZe d eZed ed ed ed ed ed ed ejZedZeddddZedddZejedddZeddddZedddZedddZ e!ddd Z"e#dd!d"Z$dS)#rHz!(0|([1-9]\d*))(\.(0|([1-9]\d*)))+z[a-zA-Z][a-zA-Z\d-]*z!\\([\\ #=\"\+,;<>]|[\da-zA-Z]{2})z7[\x01-\x1f\x21\x24-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z3[\x01-\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z7[\x01-\x1F\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z[\x80-]|z ( (z!) ( (z)* (z$) )? )? z#([\da-zA-Z]{2})+NrcCs||_d|_dS)Nr)_data_idx)r]rrrrr^sz_RFC4514NameParser.__init__r_cCs|jt|jkSr`)rrCrrarrr _has_datasz_RFC4514NameParser._has_datacCs|r|j|jSdSr`)rrrrarrr_peeks z_RFC4514NameParser._peek)chr+cCs"||krt|jd7_dS)Nr@)rrVr)r]rrrr _read_chars z_RFC4514NameParser._read_charcCs<|j|j|jd}|durt|}|jt|7_|S)N)pos)matchrrrVrBrC)r]patrr*rrr_read_res z_RFC4514NameParser._read_recCs4|g}|r,|d||q t|S)Nr2) _parse_rdnrrappendrrrrrrs   z_RFC4514NameParser.parsecCs8|g}|dkr0|d||q t|S)Nr1) _parse_narrrrw)r]Znasrrrrs    z_RFC4514NameParser._parse_rdncCsz||j}Wn4tyD||j}t|}|dur@tYn 0t|}|d|dkr||j }t |dd }n||j }t|}t||S)Nrer-r@)r_OID_RErV _DESCR_RE_NAME_TO_NAMEOIDrZrrr _HEXSTRING_REr; unhexlifyr= _STRING_RErJrK)r]Z oid_valuenamerMrZ raw_valuerrrrs        z_RFC4514NameParser._parse_na)%rrrrecompilerrZ_PAIRrIZ_LUTF1Z_SUTF1Z_TUTF1rDsys maxunicodeZ_UTFMBZ _LEADCHARZ _STRINGCHARZ _TRAILCHARVERBOSErrrRr^rsrrprrrrrrrrwrrKrrrrrrHesH      rH)0r;rrrprWZ cryptographyrZ"cryptography.hazmat.bindings._rustrrZcryptography.x509.oidrrEnumrZ_ASN1_TYPE_TO_ENUMrSrrTZ SERIAL_NUMBERZ DN_QUALIFIERZ EMAIL_ADDRESSrZDOMAIN_COMPONENTr"Dict__annotations__MappingrRruZ COMMON_NAMEZ LOCALITY_NAMEZSTATE_OR_PROVINCE_NAMEZORGANIZATION_NAMEZORGANIZATIONAL_UNIT_NAMEZSTREET_ADDRESSZUSER_IDr'itemsrrqr:r?rJrKrwrrHrrrrsD     g5[