3 L]@sddlmZmZmZddlmZddlZddlmZddl m Z m Z GdddeZ e dd e DZeZe je je je je je je je je je je je jiZe jd e jd e jd e jd e jde jde jde jde j di Z!ddZ"GdddeZ#GdddeZ$GdddeZ%dS))absolute_importdivisionprint_function)EnumN)utils)NameOIDObjectIdentifierc@s4eZdZdZdZdZdZdZdZdZ dZ d Z d Z d S) _ASN1Type N) __name__ __module__ __qualname__ UTF8StringZ NumericStringPrintableStringZ T61String IA5StringZUTCTimeZGeneralizedTimeZ VisibleStringZUniversalStringZ BMPStringrr@/tmp/pip-install-wfra5znf/cryptography/cryptography/x509/name.pyr sr ccs|]}|j|fVqdS)N)value).0irrr srZCNLZSTOZOUCZSTREETZDCZUIDcCs|jdd}|jdd}|jdd}|jdd}|jd d }|jd d }|jd d}|jdd}|ddkrtd|}|ddkr|ddd}|S)z>Escape special characters in RFC4514 Distinguished Name value.\z\\"z\"+z\+,z\,;z\;z\>z\00r# Nz\ )r+r,r.)replace)valrrr_escape_dn_value6s          r1c@sTeZdZefddZejdZejdZddZ ddZ d d Z d d Z d dZ dS) NameAttributecCst|tstdt|tjs&td|tjks:|tjkrTt|j ddkrTt dt|dkrht d|t kr~t j |tj}t|tstd||_||_||_dS) Nz2oid argument must be an ObjectIdentifier instance.z#value argument must be a text type.utf8z/Country name must be a 2 character country coderzValue cannot be an empty stringz%_type must be from the _ASN1Type enum) isinstancer TypeErrorsix text_typer COUNTRY_NAMEJURISDICTION_COUNTRY_NAMElenencode ValueError _SENTINEL_NAMEOID_DEFAULT_TYPEgetr r_oid_value_type)selfoidrrCrrr__init__Ls(      zNameAttribute.__init__rArBcCs$tj|j|jj}d|t|jfS)z Format as RFC4514 Distinguished Name string. Use short attribute name if available, otherwise fall back to OID dotted string. z%s=%s)_NAMEOID_TO_NAMEr@rEZ dotted_stringr1r)rDkeyrrrrfc4514_stringvszNameAttribute.rfc4514_stringcCs&t|tstS|j|jko$|j|jkS)N)r5r2NotImplementedrEr)rDotherrrr__eq__s  zNameAttribute.__eq__cCs ||k S)Nr)rDrKrrr__ne__szNameAttribute.__ne__cCst|j|jfS)N)hashrEr)rDrrr__hash__szNameAttribute.__hash__cCs dj|S)Nz/)format)rDrrr__repr__szNameAttribute.__repr__N)rrrr>rFrZread_only_propertyrErrIrLrMrOrQrrrrr2Ks '    r2c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)RelativeDistinguishedNamecCs\t|}|stdtdd|Ds.td||_t||_t|jt|krXtddS)Nz-a relative distinguished name cannot be emptycss|]}t|tVqdS)N)r5r2)rxrrrrsz5RelativeDistinguishedName.__init__..z/attributes must be an iterable of NameAttributez$duplicate attributes are not allowed)listr=allr6 _attributes frozenset_attribute_setr;)rD attributesrrrrFs z"RelativeDistinguishedName.__init__csfdd|DS)Ncsg|]}|jkr|qSr)rE)rr)rErr szDRelativeDistinguishedName.get_attributes_for_oid..r)rDrEr)rErget_attributes_for_oidsz0RelativeDistinguishedName.get_attributes_for_oidcCsdjdd|jDS)z Format as RFC4514 Distinguished Name string. Within each RDN, attributes are joined by '+', although that is rarely used in certificates. r%css|]}|jVqdS)N)rI)rattrrrrrsz;RelativeDistinguishedName.rfc4514_string..)joinrV)rDrrrrIsz(RelativeDistinguishedName.rfc4514_stringcCst|tstS|j|jkS)N)r5rRrJrX)rDrKrrrrLs z RelativeDistinguishedName.__eq__cCs ||k S)Nr)rDrKrrrrMsz RelativeDistinguishedName.__ne__cCs t|jS)N)rNrX)rDrrrrOsz"RelativeDistinguishedName.__hash__cCs t|jS)N)iterrV)rDrrr__iter__sz"RelativeDistinguishedName.__iter__cCs t|jS)N)r;rV)rDrrr__len__sz!RelativeDistinguishedName.__len__cCsdj|jS)Nz)rPrI)rDrrrrQsz"RelativeDistinguishedName.__repr__N) rrrrFr[rIrLrMrOr_r`rQrrrrrRs rRc@sheZdZddZddZddZeddZd d Zd d Z d dZ ddZ ddZ ddZ ddZdS)NamecCsRt|}tdd|Dr,dd|D|_n"tdd|DrF||_ntddS)Ncss|]}t|tVqdS)N)r5r2)rrSrrrrsz Name.__init__..cSsg|]}t|gqSr)rR)rrSrrrrZsz!Name.__init__..css|]}t|tVqdS)N)r5rR)rrSrrrrszNattributes must be a list of NameAttribute or a list RelativeDistinguishedName)rTrUrVr6)rDrYrrrrFsz Name.__init__cCsdjdd|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. r&css|]}|jVqdS)N)rI)rr\rrrrsz&Name.rfc4514_string..)r]rV)rDrrrrIs zName.rfc4514_stringcsfdd|DS)Ncsg|]}|jkr|qSr)rE)rr)rErrrZsz/Name.get_attributes_for_oid..r)rDrEr)rErr[szName.get_attributes_for_oidcCs|jS)N)rV)rDrrrrdnssz Name.rdnscCs |j|S)N)Zx509_name_bytes)rDbackendrrr public_bytesszName.public_bytescCst|tstS|j|jkS)N)r5rarJrV)rDrKrrrrLs z Name.__eq__cCs ||k S)Nr)rDrKrrrrMsz Name.__ne__cCstt|jS)N)rNtuplerV)rDrrrrOsz Name.__hash__ccs(x"|jD]}x|D] }|VqWqWdS)N)rV)rDrdnZavarrrr_s  z Name.__iter__cCstdd|jDS)Ncss|]}t|VqdS)N)r;)rrfrrrrszName.__len__..)sumrV)rDrrrr`sz Name.__len__cCs,tjrdj|jjdSdj|jSdS)Nz r3)r7PY2rPrIr<)rDrrrrQsz Name.__repr__N)rrrrFrIr[propertyrbrdrLrMrOr_r`rQrrrrras  ra)& __future__rrrenumrr7Z cryptographyrZcryptography.x509.oidrrr dictZ_ASN1_TYPE_TO_ENUMobjectr>r9rr:Z SERIAL_NUMBERZ DN_QUALIFIERZ EMAIL_ADDRESSrZDOMAIN_COMPONENTr?Z COMMON_NAMEZ LOCALITY_NAMEZSTATE_OR_PROVINCE_NAMEZORGANIZATION_NAMEZORGANIZATIONAL_UNIT_NAMEZSTREET_ADDRESSZUSER_IDrGr1r2rRrarrrrs4     H1