ok

Mini Shell

Direktori : /lib/python3.6/site-packages/josepy/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/josepy/__pycache__/jwa.cpython-36.pyc

3

�}:a� �@s�dZddlZddlZddlmZmZddlZddlm	Z	ddl
mZddl
mZddl
mZmZddlmZdd	lmZdd
lmZmZmZddlmZeje�ZGdd
�d
ej�ZGdd�dee�ZGdd�de�ZGdd�d�Z Gdd�de e�Z!Gdd�de e�Z"Gdd�de�Z#ej$edej%��Z&ej$edej'��Z(ej$edej)��Z*ej$e!dej%��Z+ej$e!dej'��Z,ej$e!dej)��Z-ej$e"d ej%��Z.ej$e"d!ej'��Z/ej$e"d"ej)��Z0ej$e#d#ej%��Z1ej$e#d$ej'��Z2ej$e#d%ej)��Z3dS)&zZJSON Web Algorithms.

https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40

�N)�Dict�Type)�default_backend)�hashes)�hmac)�padding�ec)�decode_dss_signature)�encode_dss_signature)�errors�
interfaces�jwk)�Hashablec@seZdZdZdS)�JWAzJSON Web Algorithm.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/jwa.pyrsrc@s~eZdZUdZiZeeefdd�Zdd�Z	dd�Z
edd	��Zd
d�Z
edd
��Zejdd��Zejdd��Zdd�ZdS)�JWASignaturez-Base class for JSON Web Signature Algorithms.cCs
||_dS)N)�name)�selfrrrr�__init__$szJWASignature.__init__cCst|t�stS|j|jkS)N)�
isinstancer�NotImplementedr)r�otherrrr�__eq__'s
zJWASignature.__eq__cCst|j|jf�S)N)�hash�	__class__r)rrrr�__hash__,szJWASignature.__hash__cCs||j|j<|S)z(Register class for JSON deserialization.)�
SIGNATURESr)�clsZ
signature_clsrrr�register/szJWASignature.registercCs|jS)N)r)rrrr�to_partial_json5szJWASignature.to_partial_jsoncCs
|j|S)N)r!)r"Zjobjrrr�	from_json8szJWASignature.from_jsoncCs
t��dS)zSign the ``msg`` using ``key``.N)�NotImplementedError)r�key�msgrrr�sign<szJWASignature.signcCs
t��dS)z-Verify the ``msg`` and ``sig`` using ``key``.N)r&)rr'r(�sigrrr�verifyAszJWASignature.verifycCs|jS)N)r)rrrr�__repr__FszJWASignature.__repr__N)rrrrr!r�strrrrr �classmethodr#r$r%�abc�abstractmethodr)r+r,rrrrr s
rcs2eZdZejZ�fdd�Zdd�Zdd�Z�Z	S)�_JWAHScst�j|�|�|_dS)N)�superrr)rr�hash_)rrrrMsz_JWAHS.__init__cCs&tj||jt�d�}|j|�|j�S)N)�backend)r�HMACrr�update�finalize)rr'r(�signerrrrr)Qs
z_JWAHS.signcCshtj||jt�d�}|j|�y|j|�Wn2tjjk
r^}zt	j
|dd�dSd}~XnXdSdS)N)r4T)�exc_infoF)rr5rrr6r+�cryptography�
exceptions�InvalidSignature�logger�debug)rr'r(r*�verifier�errorrrrr+Vs
z
_JWAHS.verify)
rrrr
ZJWKOct�ktyrr)r+�
__classcell__rr)rrr1Jsr1c@s*eZdZejZeZeZdd�Z	dd�Z
dS)�_JWARSAcCst|d�}y*|r"|j||j|j�S|j|j|j�}Wnvtk
rn}ztj|dd�tj	d��WYdd}~Xn>t
k
r�}z"tj|dd�tj	t|���WYdd}~XnX|j|�y|j
�St
k
�r�}z"tj|dd�tj	t|���WYdd}~XnXdS)zSign the ``msg`` using ``key``.r)T)r9z%Public key cannot be used for signingN)�hasattrr)rrr8�AttributeErrorr=r>r�Error�
ValueErrorr-r6r7)rr'r(�new_apir8r@rrrr)gs"
 
z_JWARSA.signcCs�t|d�}|s*|j||j|j�}|j|�y&|rF|j|||j|j�n|j�Wn2tjjk
r�}zt	j
|dd�dSd}~XnXdSdS)z,Verify the ``msg` and ``sig`` using ``key``.r+T)r9FN)rDr?rrr6r+r:r;r<r=r>)rr'r(r*rHr?r@rrrr+|s

z_JWARSA.verifyN)rrrr
ZJWKRSArArrrr)r+rrrrrCbs
rCcseZdZ�fdd�Z�ZS)�_JWARScs"t�j|�tj�|_|�|_dS)N)r2rrZPKCS1v15r)rrr3)rrrr�s
z_JWARS.__init__)rrrrrBrr)rrrI�srIcseZdZ�fdd�Z�ZS)�_JWAPScs4t�j|�tjtj|��tjjd�|_|�|_dS)N)ZmgfZsalt_length)r2rrZPSSZMGF1Z
MAX_LENGTHr)rrr3)rrrr�s

z_JWAPS.__init__)rrrrrBrr)rrrJ�srJcsBeZdZejZ�fdd�Zdd�Zdd�Zdd�Z	d	d
�Z
�ZS)�_JWAECcst�j|�|�|_dS)N)r2rr)rrr3)rrrr�sz_JWAEC.__init__cCsB|j||�}t|�\}}tjj|j�}|j|dd�|j|dd�S)zSign the ``msg`` using ``key``.�big)�length�	byteorder)�_signr	r
�JWKEC�expected_length_for_curve�curve�to_bytes)rr'r(r*ZdrZdsrMrrrr)�s
z_JWAEC.signcCst|d�}y.|r$|j|tj|j��S|jtj|j��}Wnvtk
rr}ztj|dd�t	j
d��WYdd}~Xn>tk
r�}z"tj|dd�t	j
t|���WYdd}~XnX|j
|�y|j�Stk
�r}z"tj|dd�t	j
t|���WYdd}~XnXdS)Nr)T)r9z%Public key cannot be used for signing)rDr)r�ECDSArr8rEr=r>rrFrGr-r6r7)rr'r(rHr8r@rrrrO�s"
 
z_JWAEC._signcCs^tjj|j�}t|�d|kr"dSttj|d|�dd�tj||d�dd��}|j|||�S)z,Verify the ``msg` and ``sig`` using ``key``.�FrrL)rNN)	r
rPrQrR�lenr
�int�
from_bytes�_verify)rr'r(r*Zrlen�asn1sigrrrr+�sz
_JWAEC.verifycCs�t|d�}|s,|j|tj|j��}|j|�y(|rJ|j||tj|j��n|j�Wn2tjj	k
r�}zt
j|dd�dSd}~XnXdSdS)Nr+T)r9F)rDr?rrTrr6r+r:r;r<r=r>)rr'r(rZrHr?r@rrrrY�s

z_JWAEC._verify)rrrr
rPrArr)rOr+rYrBrr)rrrK�srK�HS256�HS384�HS512�RS256�RS384�RS512�PS256�PS384�PS512�ES256�ES384�ES512)4rr/ZloggingZtypingrrZcryptography.exceptionsr:Zcryptography.hazmat.backendsrZcryptography.hazmat.primitivesrrZ)cryptography.hazmat.primitives.asymmetricrrZ/cryptography.hazmat.primitives.asymmetric.utilsr	r
Zjosepyrrr
�collections.abcrZ	getLoggerrr=ZJSONDeSerializablerrr1rCrIrJrKr#ZSHA256r[ZSHA384r\ZSHA512r]r^r_r`rarbrcrdrerfrrrr�<module>s@
*-
B

Zerion Mini Shell 1.0