a BgA'@s$dZddlZddlZddlZddlmZmZddlmZddl m Z m Z m Z m Z mZmZmZmZddlmZmZddlmZe edd d ZGd d d ZGd ddZGdddeZGdddeZedddZGdddeeZGdddeeZGdddZ eee ej!e"ej!e"<dS)zJOSE utilities.N)HashableMapping) ModuleType)AnyCallableIteratorListTupleTypeVarUnioncast)ecrsa)crypto)funcreturncCstt|SN) classmethodabcabstractmethod)rr//usr/lib/python3.9/site-packages/josepy/util.pyabstractclassmethodsrc@s~eZdZdZeejejfddddZe e dddZ ej fe ed d d Ze ed d dZe dddZe dddZdS)ComparableX509zWrapper for OpenSSL.crypto.X509** objects that supports __eq__. :ivar wrapped: Wrapped certificate or certificate request. :type wrapped: `OpenSSL.crypto.X509` or `OpenSSL.crypto.X509Req`. N)wrappedrcCs&t|tjst|tjsJ||_dSr) isinstancerX509X509Reqrselfrrrr__init__szComparableX509.__init__namercCs t|j|Sr)getattrrrr"rrr __getattr__szComparableX509.__getattr__)filetypercCs*t|jtjrt||jSt||jS)aNDumps the object into a buffer with the specified encoding. :param int filetype: The desired encoding. Should be one of `OpenSSL.crypto.FILETYPE_ASN1`, `OpenSSL.crypto.FILETYPE_PEM`, or `OpenSSL.crypto.FILETYPE_TEXT`. :returns: Encoded X509 object. :rtype: bytes )rrrrZdump_certificateZdump_certificate_request)rr&rrr_dump!s zComparableX509._dumpotherrcCs t||jstS||kSr)r __class__NotImplementedr'rr)rrr__eq__3s zComparableX509.__eq__rcCst|j|fSr)hashr*r'rrrr__hash__8szComparableX509.__hash__cCsd|jj|jSNz <{0}({1!r})>)formatr*__name__rr0rrr__repr__;szComparableX509.__repr__)r4 __module__ __qualname____doc__r rrrr strrr%Z FILETYPE_ASN1intbytesr'boolr-r1r5rrrrrsrc@seZdZUdZeZegefed<e e j e j e je jfdddZeedddZeed d d Zed d dZdd ddZdS) ComparableKeyznComparable wrapper for ``cryptography`` keys. See https://github.com/pyca/cryptography/issues/2122. r1)rcCs ||_dSr)_wrappedrrrrr Hs zComparableKey.__init__r!cCs t|j|Sr)r#r>r$rrrr%SszComparableKey.__getattr__r(cCs`t||jr|jj|jjur tSt|jdr<||kSt|jdrX||kStSdS)Nprivate_numberspublic_numbers)rr*r>r+hasattrr?r@r,rrrr-Vs   zComparableKey.__eq__r.cCsd|jj|jSr2)r3r*r4r>r0rrrr5cszComparableKey.__repr__cCs(t|jtjtjfr|S||jS)zGet wrapped public key.)rr>rRSAPublicKeyWithSerializationr 'EllipticCurvePublicKeyWithSerializationr* public_keyr0rrrrDfs  zComparableKey.public_keyN)r4r6r7r8r+r1rr:__annotations__r rRSAPrivateKeyWithSerializationrBr (EllipticCurvePrivateKeyWithSerializationrCr r9rr%r<r-r5rDrrrrr=?s   r=c@seZdZdZedddZdS)ComparableRSAKeyzWrapper for ``cryptography`` RSA keys. Wraps around: - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey` - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` r.c Csxt|jtjrD|}|j}t|j|j|j |j |j |j |j |jfSt|jtjrn|}t|j|j |jfStdSr)rr>rrFr?r@r/r*pqZdmp1Zdmq1ZiqmpnerBNotImplementedErrorrZprivZpubrrrr1{s"zComparableRSAKey.__hash__Nr4r6r7r8r:r1rrrrrHqs rHc@seZdZdZedddZdS)ComparableECKeyzWrapper for ``cryptography`` EC keys. Wraps around: - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` r.cCstt|jtjr:|}|j}t|j|jj |j |j |j fSt|jtj rj|}t|j|jj |j |j fStdSr)rr>r rGr?r@r/r*Zcurver"xyZ private_valuerCrMrNrrrr1szComparableECKey.__hash__NrOrrrrrPsrPGenericImmutableMap ImmutableMap)boundc@seZdZUdZdZeedfed<eddddZ e ee d d d Z eed d dZ e edddZedddZedddZeeddddZedddZdS)rTz5Immutable key to value mapping with attribute access.r. __slots__N)kwargsrcKs\t|t|jkr8tdd|j|r0d|nd|jD]}t||||q>dS)NzA__init__() takes exactly the following arguments: {0} ({1} given), Znone)setrV TypeErrorr3joinobject __setattr__pop)rrWslotrrrr s zImmutableMap.__init__)rrWrcKsi||}t|fi|S)zReturn updated map.)type)rrWitemsrrrupdates zImmutableMap.updatekeyrcCs,z t||WSty&t|Yn0dSr)r#AttributeErrorKeyErrorrrdrrr __getitem__s  zImmutableMap.__getitem__r.cCs t|jSr)iterrVr0rrr__iter__szImmutableMap.__iter__cCs t|jSr)lenrVr0rrr__len__szImmutableMap.__len__csttfddjDS)Nc3s|]}t|VqdSr)r#).0r_r0rr z(ImmutableMap.__hash__..)r/tuplerVr0rr0rr1szImmutableMap.__hash__r"valuercCs tddSNzcan't set attributererr"rrrrrr]szImmutableMap.__setattr__cCs$d|jjddd|DS)Nz{0}({1})rXcss|]\}}d||VqdSz {0}={1!r}Nr3rmrdrrrrrrnroz(ImmutableMap.__repr__..)r3r*r4r[rar0rrrr5szImmutableMap.__repr__)r4r6r7r8rVr r9rErr rSrbrhrrjr:rlr1r]r5rrrrrTs  c@seZdZdZdZeeddddZeeddd Ze ed d d Z e d d dZ e e eefdfd ddZe d ddZeedddZeeddddZed ddZdS) frozendictzFrozen dictionary.)_items_keysN)argsrWrcOsh|r|st|}n*t|dkr6t|dtr6|d}ntt|d|t|dtt| dS)Nrrzr{) dictrkrrrZr\r]rpsortedkeys)rr|rWrarrrr s  zfrozendict.__init__rccCs |j|Sr)rzrgrrrrhszfrozendict.__getitem__r.cCs t|jSr)rir{r0rrrrjszfrozendict.__iter__cCs t|jSr)rkrzr0rrrrlszfrozendict.__len__.cstfddjDS)Nc3s|]}||fVqdSrr)rmrdr0rrrnroz+frozendict._sorted_items..)rpr{r0rr0r _sorted_itemsszfrozendict._sorted_itemscCs t|Sr)r/rr0rrrr1szfrozendict.__hash__r!cCs,z |j|WSty&t|Yn0dSr)rzrfrer$rrrr%s  zfrozendict.__getattr__rqcCs tddSrsrtrurrrr]szfrozendict.__setattr__cCsdddd|DS)Nzfrozendict({0})rXcss|]\}}d||VqdSrvrwrxrrrrnroz&frozendict.__repr__..)r3r[rr0rrrr5szfrozendict.__repr__)r4r6r7r8rVrr r9rhrrjr:rlr rr1r%r]r5rrrrrys ryc@sdeZdZdZeddddZeedddZeedd d d Z eddd d Z e edddZ dS)_UtilDeprecationModulez Internal class delegating to a module, and displaying warnings when attributes related to the deprecated "abstractclassmethod" attributes in the josepy.util module. N)modulercCs||jd<dSN_module)__dict__)rrrrrr sz_UtilDeprecationModule.__init__)attrrcCs$|dkrtjdtddt|j|S)NrzThe abstractclassmethod attribute in josepy.util is deprecated and will be removed soon. Please use the built-in decorators @classmethod and @abc.abstractmethod together instead.) stacklevel)warningswarnDeprecationWarningr#rrrrrrr%sz"_UtilDeprecationModule.__getattr__)rrrrcCst|j||dSr)setattrr)rrrrrrrr]sz"_UtilDeprecationModule.__setattr__cCst|j|dSr)delattrrrrrr __delattr__sz"_UtilDeprecationModule.__delattr__r.cCsdgt|jSr)dirrr0rrr__dir__sz_UtilDeprecationModule.__dir__) r4r6r7r8rr r9rr%r]rrrrrrrrs  r)#r8rsysrcollections.abcrrtypesrtypingrrrrr r r r Z)cryptography.hazmat.primitives.asymmetricr rZOpenSSLrrrrr=rHrPrSrTryrmodulesr4rrrrs$ ( -2 /3