3
“k®Zá ã @ s` d dl Zd dlZd dlZd dlmZ d dlmZ d dlm Z d dl
mZmZ G dd„ de ƒZ
dS )é N)ÚRSA)Ú
PKCS1_v1_5)Ú Algorithm)Ústring_typesÚ text_typec @ sH e Zd ZdZejjZejjZejjZdd„ Z dd„ Z
dd„ Zdd „ Zd
S )ÚRSAAlgorithmzé
Performs signing and verification operations using
RSASSA-PKCS-v1_5 and the specified hash function.
This class requires PyCrypto package to be installed.
This is based off of the implementation in PyJWT 0.3.2
c C s
|| _ d S )N)Úhash_alg)Úselfr © r
ú/usr/lib/python3.6/pycrypto.pyÚ__init__ s zRSAAlgorithm.__init__c C sF t |tjƒr|S t |tƒr:t |tƒr.|jdƒ}tj|ƒ}ntdƒ‚|S )Nzutf-8z&Expecting a PEM- or RSA-formatted key.)Ú
isinstancer Z_RSAobjr r ÚencodeZ importKeyÚ TypeError)r Úkeyr
r
r Úprepare_key s
zRSAAlgorithm.prepare_keyc C s t j|ƒj| jj|ƒƒS )N)r ÚnewÚsignr )r Úmsgr r
r
r r * s zRSAAlgorithm.signc C s t j|ƒj| jj|ƒ|ƒS )N)r r Úverifyr )r r r Zsigr
r
r r - s zRSAAlgorithm.verifyN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚCryptoZHashZSHA256ZSHA384ZSHA512r r r r r
r
r
r r s r )ZCrypto.Hash.SHA256r ZCrypto.Hash.SHA384ZCrypto.Hash.SHA512ZCrypto.PublicKeyr ZCrypto.Signaturer Zjwt.algorithmsr Z
jwt.compatr r r r
r
r
r Ú