????

Your IP : 3.23.61.5


Current Path : /lib/python3.6/site-packages/josepy/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/josepy/__pycache__/util.cpython-36.opt-1.pyc

3

�}:a!�@s�dZddlmZmZddlZddlmZddlmZm	Z	Gdd�de
�ZGdd	�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�Zd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
||_dS)N)�wrapped)rrrrrr
%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

        )�
isinstancer�OpenSSL�cryptoZX509Zdump_certificateZdump_certificate_request)rZfiletype�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)rrrr�__hash__EszComparableX509.__hash__cCsdj|jj|j�S)Nz<{0}({1!r})>)�formatr
rr)rrrr�__repr__HszComparableX509.__repr__N)
rrrrr
rrrZ
FILETYPE_ASN1rr!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)rrrrrr
TszComparableKey.__init__cCst|j|�S)N)rr')rrrrrrWszComparableKey.__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))rr rrrr!ZszComparableKey.__eq__cCsdj|jj|j�S)Nz<{0}({1!r})>)r$r
rr')rrrrr%fszComparableKey.__repr__cCs|j|jj��S)zGet wrapped public key.)r
r'�
public_key)rrrrr+iszComparableKey.public_keyN)rrrrrr#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
|jf�SdS)N)rr'rZ(EllipticCurvePrivateKeyWithSerializationr(r)r"r
Zcurver�x�yZ
private_valueZ'EllipticCurvePublicKeyWithSerialization)rr1r2rrrr#�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+rrrrr3�sr3c@sTeZdZdZfZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�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)rr?�itemsrrr�update�szImmutableMap.updatecCs,y
t||�Stk
r&t|��YnXdS)N)r�AttributeError�KeyError)rr6rrr�__getitem__�s
zImmutableMap.__getitem__cCs
t|j�S)N)�iterr9)rrrr�__iter__�szImmutableMap.__iter__cCs
t|j�S)N)�lenr9)rrrr�__len__�szImmutableMap.__len__cstt�fdd��jD���S)Nc3s|]}t�|�VqdS)N)r)�.0r@)rrr�	<genexpr>�sz(ImmutableMap.__hash__.<locals>.<genexpr>)r"�tupler9)rr)rrr#�szImmutableMap.__hash__cCstd��dS)Nzcan't set attribute)rD)rr�valuerrrr=�szImmutableMap.__setattr__cCs$dj|jjdjdd�|j�D���S)Nz{0}({1})z, css|]\}}dj||�VqdS)z	{0}={1!r}N)r$)rKr6rNrrrrL�sz(ImmutableMap.__repr__.<locals>.<genexpr>)r$r
rr;rB)rrrrr%�szImmutableMap.__repr__N)
rrrrr9r
rCrFrHrJr#r=r%rrrrr7�s	r7c@s\eZdZdZdZdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
frozendictzFrozen dictionary.�_items�_keyscOsj|r|rt|�}n*t|�dkr8t|dt�r8|d}nt��tj|d|�tj|dtt|j	����dS)N�rrPrQ)
�dictrIrrr:r<r=rM�sorted�keys)r�argsr?rBrrrr
�s


zfrozendict.__init__cCs
|j|S)N)rP)rr6rrrrF�szfrozendict.__getitem__cCs
t|j�S)N)rGrQ)rrrrrH�szfrozendict.__iter__cCs
t|j�S)N)rIrP)rrrrrJ�szfrozendict.__len__cst�fdd��jD��S)Nc3s|]}|�|fVqdS)Nr)rKr6)rrrrL�sz+frozendict._sorted_items.<locals>.<genexpr>)rMrQ)rr)rr�
_sorted_items�szfrozendict._sorted_itemscCst|j��S)N)r"rW)rrrrr#�szfrozendict.__hash__cCs,y
|j|Stk
r&t|��YnXdS)N)rPrErD)rrrrrr�s
zfrozendict.__getattr__cCstd��dS)Nzcan't set attribute)rD)rrrNrrrr=�szfrozendict.__setattr__cCsdjdjdd�|j�D���S)Nzfrozendict({0})z, css|]\}}dj||�VqdS)z	{0}={1!r}N)r$)rKr6rNrrrrL�sz&frozendict.__repr__.<locals>.<genexpr>)r$r;rW)rrrrr%�szfrozendict.__repr__N)rPrQ)rrrrr9r
rFrHrJrWr#rr=r%rrrrrO�srO)r�collections.abcrrrZcryptography.hazmat.backendsrZ)cryptography.hazmat.primitives.asymmetricrr�classmethodrrr&r,r3r7rOrrrr�<module>s/"-