o h9Ra(@sdZddlZddlmZddlmZmZmZmZm Z m Z m Z ddl m Z mZddlZddlZddlmZddlmZmZded efd d ZGd d d ZGdddZGdddeZGdddeZGdddee ZGdddee ZGdddZe eeeje eje <dS)zJOSE utilities.N) ModuleType)UnionAnyCallableIteratorTupleListcast)HashableMapping)crypto)ecrsafuncreturncCstt|SN) classmethodabcabstractmethod)rr-/usr/lib/python3/dist-packages/josepy/util.pyabstractclassmethodrc@seZdZdZdeejejfddfddZde de fdd Z ej fd e defd d Zd e defddZde fddZde fddZdS)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`. wrappedrNcCs&t|tjst|tjsJ||_dSr) isinstancer X509X509Reqrselfrrrr__init__s zComparableX509.__init__namecC t|j|Sr)getattrrrr!rrr __getattr__ zComparableX509.__getattr__filetypecCs*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 )rrr rdump_certificatedump_certificate_request)rr'rrr_dump"s zComparableX509._dumpothercCs t||jstS||kSr)r __class__NotImplementedr*rr+rrr__eq__4s zComparableX509.__eq__cCst|j|fSr)hashr,r*rrrr__hash__:zComparableX509.__hash__cCd|jj|jSNz <{0}({1!r})>)formatr,__name__rr1rrr__repr__=r3zComparableX509.__repr__)r7 __module__ __qualname____doc__rr rrr strrr% FILETYPE_ASN1intbytesr*boolr/r2r8rrrrrsrc@seZdZUdZeZegefed<de e j e j e je jffddZdedefdd Zd edefd d Zdefd dZdddZdS) ComparableKeyznComparable wrapper for ``cryptography`` keys. See https://github.com/pyca/cryptography/issues/2122. r2rcCs ||_dSr)_wrappedrrrrr Is zComparableKey.__init__r!rcCr"r)r#rBr$rrrr%Qr&zComparableKey.__getattr__r+cCs\t||jr|jj|jjurtSt|jdr||kSt|jdr,||kStS)Nprivate_numberspublic_numbers)rr,rBr-hasattrrCrDr.rrrr/Ts   zComparableKey.__eq__cCr4r5)r6r,r7rBr1rrrr8`r3zComparableKey.__repr__cCs(t|jtjtjfr |S||jS)zGet wrapped public key.)rrBrRSAPublicKeyWithSerializationr 'EllipticCurvePublicKeyWithSerializationr, public_keyr1rrrrHcs zComparableKey.public_keyN)rrA)r7r9r:r;r-r2rr>__annotations__rrRSAPrivateKeyWithSerializationrFr (EllipticCurvePrivateKeyWithSerializationrGr r<rr%r@r/r8rHrrrrrAAs   rAc@eZdZdZdefddZdS)ComparableRSAKeyzWrapper for ``cryptography`` RSA keys. Wraps around: - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey` - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` rc Cstt|jtjr"|}|j}t|j|j|j |j |j |j |j |jfSt|jtjr7|}t|j|j |jfStr)rrBrrJrCrDr0r,pqdmp1dmq1iqmpnerFNotImplementedErrorrprivpubrrrr2vszComparableRSAKey.__hash__Nr7r9r:r;r>r2rrrrrMls rMc@rL)ComparableECKeyzWrapper for ``cryptography`` RSA keys. Wraps around: - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` rcCspt|jtjr|}|j}t|j|jj |j |j |j fSt|jtj r5|}t|j|jj |j |j fStr)rrBr rKrCrDr0r,curver!xy private_valuerGrUrVrrrr2szComparableECKey.__hash__NrYrrrrrZsrZc@seZdZUdZdZeedfed< deddfdd Z deddfd d Z d edefd dZ de efddZ defddZdefddZdededdfddZdefddZdS) ImmutableMapz5Immutable key to value mapping with attribute access.r. __slots__kwargsrNcKs`t|t|jkrtdd|j|rd|d|jD] }t||||q!dS)NzA__init__() takes exactly the following arguments: {0} ({1} given), none)setr` TypeErrorr6joinobject __setattr__pop)rraslotrrrr s   zImmutableMap.__init__cKsi||}t|di|S)zReturn updated map.Nr)type)rraitemsrrrupdates zImmutableMap.updatekeycCs$zt||WStyt|wr)r#AttributeErrorKeyErrorrrnrrr __getitem__   zImmutableMap.__getitem__cC t|jSr)iterr`r1rrr__iter__ zImmutableMap.__iter__cCrtr)lenr`r1rrr__len__rwzImmutableMap.__len__csttfddjDS)Nc3s|]}t|VqdSr)r#).0rjr1rr sz(ImmutableMap.__hash__..)r0tupler`r1rr1rr2szImmutableMap.__hash__r!valuecCtdNzcan't set attributerorr!r}rrrrhzImmutableMap.__setattr__cCs$d|jjddd|DS)Nz{0}({1})rbcs |] \}}d||VqdSz {0}={1!r}Nr6rzrnr}rrrr{s  z(ImmutableMap.__repr__..)r6r,r7rfrlr1rrrr8s zImmutableMap.__repr__)r7r9r:r;r`rr<rIrr rmrrrrvr>ryr2rhr8rrrrr_s  r_c@seZdZdZdZdededdfddZd edefd d Zde efd d Z de fddZ de e eefdffddZde fddZdedefddZdededdfddZdefddZdS) frozendictzFrozen dictionary.)_items_keysargsrarNcOsh|r |s t|}nt|dkrt|dtr|d}ntt|d|t|dtt| dS)Nrrr) dictrxrr rergrhr|sortedkeys)rrrarlrrrr s  zfrozendict.__init__rncCs |j|Sr)rrqrrrrrrwzfrozendict.__getitem__cCrtr)rurr1rrrrvrwzfrozendict.__iter__cCrtr)rxrr1rrrryrwzfrozendict.__len__.cstfddjDS)Nc3s|] }||fVqdSrr)rzrnr1rrr{sz+frozendict._sorted_items..)r|rr1rr1r _sorted_itemsszfrozendict._sorted_itemscCs t|Sr)r0rr1rrrr2r&zfrozendict.__hash__r!cCs$z|j|WStyt|wr)rrpror$rrrr%rszfrozendict.__getattr__r}cCr~rrrrrrrhrzfrozendict.__setattr__cCsdddd|DS)Nzfrozendict({0})rbcsrrrrrrrr{s  z&frozendict.__repr__..)r6rfrr1rrrr8s zfrozendict.__repr__)r7r9r:r;r`rr r<rrrrvr>ryrrr2r%rhr8rrrrrs rc@sneZdZdZdeddfddZdedefdd Zded eddfd d Z deddfd dZ de efddZ dS)_UtilDeprecationModulez Internal class delegating to a module, and displaying warnings when attributes related to the deprecated "abstractclassmethod" attributes in the josepy.util module. modulerNcCs||jd<dSN_module)__dict__)rrrrrr rz_UtilDeprecationModule.__init__attrcCs$|dkr tjdtddt|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%s  z"_UtilDeprecationModule.__getattr__r}cCst|j||dSr)setattrr)rrr}rrrrh r3z"_UtilDeprecationModule.__setattr__cCst|j|dSr)delattrrrrrr __delattr__ z"_UtilDeprecationModule.__delattr__cCsdgt|jSr)dirrr1rrr__dir__rz_UtilDeprecationModule.__dir__) r7r9r:r;rr r<rr%rhrrrrrrrrsr)!r;rtypesrtypingrrrrrrr collections.abcr r sysrOpenSSLr )cryptography.hazmat.primitives.asymmetricr rrrrrArMrZr_rrmodulesr7rrrrs$ $ /+-2