o
    kYi                     @   s@   d dl Z d dlZd dlmZ d dlmZmZ G dd deZdS )    N)	Algorithm)string_types	text_typec                   @   sB   e Zd ZdZejZejZej	Z
dd Zdd Zdd Zdd	 Zd
S )ECAlgorithmz
    Performs signing and verification operations using
    ECDSA and the specified hash function

    This class requires the ecdsa 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   c/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/jwt/contrib/algorithms/py_ecdsa.py__init__   s   
zECAlgorithm.__init__c                 C   sz   t |tjst |tjr|S t |tr9t |tr|d}z	tj|}W |S  tjj	y8   tj|}Y |S w t
d)Nzutf-8zExpecting a PEM-formatted key.)
isinstanceecdsa
SigningKeyVerifyingKeyr   r   encodefrom_pemderUnexpectedDER	TypeError)r   keyr   r   r	   prepare_key   s   



zECAlgorithm.prepare_keyc                 C   s   |j || jtjjdS )N)hashfunc	sigencode)signr   r   utilsigencode_string)r   msgr   r   r   r	   r   3   s   
zECAlgorithm.signc                 C   s0   z|j ||| jtjjdW S  ty   Y dS w )N)r   	sigdecodeF)verifyr   r   r   sigdecode_stringAssertionError)r   r   r   sigr   r   r	   r   7   s   zECAlgorithm.verifyN)__name__
__module____qualname____doc__hashlibsha256SHA256sha384SHA384sha512SHA512r
   r   r   r   r   r   r   r	   r      s    r   )r%   r   jwt.algorithmsr   
jwt.compatr   r   r   r   r   r   r	   <module>   s
   