3 ž}:a!ã@s¬dZddlmZmZddlZddlmZddlmZm Z Gdd„de ƒZ Gdd „d ƒZ Gd d „d ƒZ Gd d „d e ƒZGdd„de ƒZGdd„deeƒZGdd„deeƒZdS)zJOSE utilities.é)ÚHashableÚMappingN)Údefault_backend)ÚecÚrsacs$eZdZdZdZ‡fdd„Z‡ZS)ÚabstractclassmethodaÚDescriptor for an abstract classmethod. It augments the :mod:`abc` framework with an abstract classmethod. This is implemented as :class:`abc.abstractclassmethod` in the standard Python library starting with version 3.2. This implementation is from a StackOverflow answer that was derived from the implementation in the Python 3.3 abc library. http://stackoverflow.com/questions/11217878/python-2-7-combine-abc-abstractmethod-and-classmethod. Tcsd|_tƒj|ƒdS)NT)Ú__isabstractmethod__ÚsuperÚ__init__)ÚselfÚtarget)Ú __class__©ú/usr/lib/python3.6/util.pyr szabstractclassmethod.__init__)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr Ú __classcell__rr)r rr s rc@sHeZdZdZdd„Zdd„Zejjfdd„Z dd „Z d d „Z d d „Z dS)ÚComparableX509zËWrapper for OpenSSL.crypto.X509** objects that supports __eq__. :ivar wrapped: Wrapped certificate or certificate request. :type wrapped: `OpenSSL.crypto.X509` or `OpenSSL.crypto.X509Req`. cCs*t|tjjƒs t|tjjƒs t‚||_dS)N)Ú isinstanceÚOpenSSLÚcryptoÚX509ZX509ReqÚAssertionErrorÚwrapped)r rrrrr %szComparableX509.__init__cCs t|j|ƒS)N)Úgetattrr)r ÚnamerrrÚ __getattr__*szComparableX509.__getattr__cCs.t|jtjjƒrtjj}ntjj}|||jƒS)aLDumps 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: str )rrrrrZdump_certificateZdump_certificate_request)r ZfiletypeÚfuncrrrÚ_dump-s  zComparableX509._dumpcCs t||jƒstS|jƒ|jƒkS)N)rr ÚNotImplementedr )r ÚotherrrrÚ__eq__?s zComparableX509.__eq__cCst|j|jƒfƒS)N)Úhashr r )r rrrÚ__hash__EszComparableX509.__hash__cCsdj|jj|jƒS)Nz <{0}({1!r})>)Úformatr rr)r rrrÚ__repr__HszComparableX509.__repr__N) rrrrr rrrZ FILETYPE_ASN1r r#r%r'rrrrrsrc@s<eZdZdZeZdd„Zdd„Zdd„Zdd „Z d d „Z d S) Ú ComparableKeyznComparable wrapper for ``cryptography`` keys. See https://github.com/pyca/cryptography/issues/2122. cCs ||_dS)N)Ú_wrapped)r rrrrr TszComparableKey.__init__cCs t|j|ƒS)N)rr))r rrrrrWszComparableKey.__getattr__cCsbt||jƒ s|jj|jjk r"tSt|jdƒr>|jƒ|jƒkSt|jdƒrZ|jƒ|jƒkStSdS)NÚprivate_numbersÚpublic_numbers)rr r)r!Úhasattrr*r+)r r"rrrr#Zs  zComparableKey.__eq__cCsdj|jj|jƒS)Nz <{0}({1!r})>)r&r rr))r rrrr'fszComparableKey.__repr__cCs|j|jjƒƒS)zGet wrapped public key.)r r)Ú public_key)r rrrr-iszComparableKey.public_keyN) rrrrr!r%r rr#r'r-rrrrr(Ls r(c@seZdZdZdd„ZdS)ÚComparableRSAKeyz×Wrapper for ``cryptography`` RSA keys. Wraps around: - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey` - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` c Csrt|jtjƒrD|jƒ}|j}t|j|j|j |j |j |j |j |jfƒSt|jtjƒrn|jƒ}t|j|j |jfƒSdS)N)rr)rZRSAPrivateKeyWithSerializationr*r+r$r ÚpÚqZdmp1Zdmq1ZiqmpÚnÚeZRSAPublicKeyWithSerialization)r ÚprivÚpubrrrr%xszComparableRSAKey.__hash__N)rrrrr%rrrrr.nsr.c@s eZdZdZdd„Zdd„ZdS)ÚComparableECKeyzæWrapper for ``cryptography`` RSA keys. Wraps around: - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` cCsnt|jtjƒr:|jƒ}|j}t|j|jj |j |j |j fƒSt|jtj ƒrj|jƒ}t|j|jj |j |j fƒSdS)N)rr)rZ(EllipticCurvePrivateKeyWithSerializationr*r+r$r ZcurverÚxÚyZ private_valueZ'EllipticCurvePublicKeyWithSerialization)r r3r4rrrr%ŒszComparableECKey.__hash__cCs4t|jdƒr|jjƒ}n|jjƒjtƒƒ}|j|ƒS)zGet wrapped public key.r-)r,r)r-r+rr )r Úkeyrrrr-—s  zComparableECKey.public_keyN)rrrrr%r-rrrrr5…s r5c@sTeZdZdZfZdd„Zdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dS)Ú ImmutableMapz5Immutable key to value mapping with attribute access.cKs`t|ƒt|jƒkr8tdjdj|jƒ|r0dj|ƒndƒƒ‚x"|jD]}tj|||j|ƒƒq@WdS)NzA__init__() takes exactly the following arguments: {0} ({1} given)z, Znone)ÚsetÚ __slots__Ú TypeErrorr&ÚjoinÚobjectÚ __setattr__Úpop)r ÚkwargsÚslotrrrr ¨s  zImmutableMap.__init__cKs||–}t|ƒf|ŽS)zReturn updated map.)Útype)r rAÚitemsrrrÚupdate±szImmutableMap.updatec Cs,y t||ƒStk r&t|ƒ‚YnXdS)N)rÚAttributeErrorÚKeyError)r r8rrrÚ __getitem__¶s zImmutableMap.__getitem__cCs t|jƒS)N)Úiterr;)r rrrÚ__iter__¼szImmutableMap.__iter__cCs t|jƒS)N)Úlenr;)r rrrÚ__len__¿szImmutableMap.__len__cstt‡fdd„ˆjDƒƒƒS)Nc3s|]}tˆ|ƒVqdS)N)r)Ú.0rB)r rrú Ãsz(ImmutableMap.__hash__..)r$Útupler;)r r)r rr%ÂszImmutableMap.__hash__cCs tdƒ‚dS)Nzcan't set attribute)rF)r rÚvaluerrrr?ÅszImmutableMap.__setattr__cCs$dj|jjdjdd„|jƒDƒƒƒS)Nz{0}({1})z, css|]\}}dj||ƒVqdS)z {0}={1!r}N)r&)rMr8rPrrrrNÊsz(ImmutableMap.__repr__..)r&r rr=rD)r rrrr'ÈszImmutableMap.__repr__N) rrrrr;r rErHrJrLr%r?r'rrrrr9¡s r9c@s\eZdZdZdZdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dS)Ú frozendictzFrozen dictionary.Ú_itemsÚ_keyscOsj|r| rt|ƒ}n*t|ƒdkr8t|dtƒr8|d}ntƒ‚tj|d|ƒtj|dtt|j ƒƒƒƒdS)NérrRrS) ÚdictrKrrr<r>r?rOÚsortedÚkeys)r ÚargsrArDrrrr Ós   zfrozendict.__init__cCs |j|S)N)rR)r r8rrrrHßszfrozendict.__getitem__cCs t|jƒS)N)rIrS)r rrrrJâszfrozendict.__iter__cCs t|jƒS)N)rKrR)r rrrrLåszfrozendict.__len__cst‡fdd„ˆjDƒƒS)Nc3s|]}|ˆ|fVqdS)Nr)rMr8)r rrrNész+frozendict._sorted_items..)rOrS)r r)r rÚ _sorted_itemsèszfrozendict._sorted_itemscCs t|jƒƒS)N)r$rY)r rrrr%ëszfrozendict.__hash__c Cs,y |j|Stk r&t|ƒ‚YnXdS)N)rRrGrF)r rrrrrîs zfrozendict.__getattr__cCs tdƒ‚dS)Nzcan't set attribute)rF)r rrPrrrr?ôszfrozendict.__setattr__cCsdjdjdd„|jƒDƒƒƒS)Nzfrozendict({0})z, css|]\}}dj||ƒVqdS)z {0}={1!r}N)r&)rMr8rPrrrrNøsz&frozendict.__repr__..)r&r=rY)r rrrr'÷szfrozendict.__repr__N)rRrS)rrrrr;r rHrJrLrYr%rr?r'rrrrrQÎs rQ)rÚcollections.abcrrrZcryptography.hazmat.backendsrZ)cryptography.hazmat.primitives.asymmetricrrÚ classmethodrrr(r.r5r9rQrrrrÚs /"-