
    ([f	                     l    d dl Z ddlmZmZmZ ddlmZmZmZ ddlm	Z	m
Z
mZmZmZ  G d d          ZdS )    N   )SIGNATURE_HMAC_SHA1SIGNATURE_PLAINTEXTSIGNATURE_RSA_SHA1)verify_hmac_sha1verify_plaintextverify_rsa_sha1)InvalidRequestErrorMissingRequiredParameterErrorUnsupportedSignatureMethodErrorInvalidNonceErrorInvalidSignatureErrorc                   V    e Zd ZeeeeeeiZ	egZ
dZed             Zd Zd Zd Zd ZdS )
BaseServeri,  c                     || j         |<   dS )a  Extend signature method verification.

        :param name: A string to represent signature method.
        :param verify: A function to verify signature.

        The ``verify`` method accept ``OAuth1Request`` as parameter::

            def verify_custom_method(request):
                # verify this request, return True or False
                return True

            Server.register_signature_method('custom-name', verify_custom_method)
        N)SIGNATURE_METHODS)clsnameverifys      V/var/www/piapp/venv/lib/python3.11/site-packages/authlib/oauth1/rfc5849/base_server.pyregister_signature_methodz$BaseServer.register_signature_method   s     '-d###    c                 $   |j                             d          }|j                             d          }|j        t          k    r|s|sdS |st	          d          	 t          |          }|dk     rt          d          | j        r.t          j                    |z
  | j        k    rt          d          n$# t          t          f$ r t          d          w xY w|st	          d          |                     ||          rt                      dS )zzValidate ``oauth_timestamp`` and ``oauth_nonce`` in HTTP request.

        :param request: OAuth1Request instance
        oauth_timestampoauth_nonceNr   zInvalid "oauth_timestamp" value)oauth_paramsgetsignature_methodr   r   intr
   EXPIRY_TIMEtime
ValueError	TypeErrorexists_noncer   )selfrequest	timestampnonces       r   validate_timestamp_and_noncez'BaseServer.validate_timestamp_and_nonce/   sD   
 (,,->??	$((77#':::  U  	C/0ABBB		III1}})*KLLL MDIKK)$;d>N$N$N)*KLLLI& 	I 	I 	I%&GHHH	I  	?/>>>UG,, 	&#%%%	& 	&s   AB7 7!Cc                    |j         }|st          d          || j        vrt                      |j        st          d          | j                            |          }|st                       ||          st                      dS )zhValidate ``oauth_signature`` from HTTP request.

        :param request: OAuth1Request instance
        oauth_signature_methodoauth_signatureN)r   r   SUPPORTED_SIGNATURE_METHODSr   	signaturer   r   r   )r%   r&   methodr   s       r   validate_oauth_signaturez#BaseServer.validate_oauth_signatureQ   s    
 ) 	J/0HIII9991333  	C/0ABBB'++F33 	41333vg 	*')))	* 	*r   c                     t                      )zGet client instance with the given ``client_id``.

        :param client_id: A string of client_id
        :return: Client instance
        NotImplementedError)r%   	client_ids     r   get_client_by_idzBaseServer.get_client_by_idg   s     "###r   c                     t                      )a	  The nonce value MUST be unique across all requests with the same
        timestamp, client credentials, and token combinations.

        :param nonce: A string value of ``oauth_nonce``
        :param request: OAuth1Request instance
        :return: Boolean
        r2   )r%   r(   r&   s      r   r$   zBaseServer.exists_nonceo   s     "###r   N)__name__
__module____qualname__r   r   r   r	   r   r   r   r-   r    classmethodr   r)   r0   r5   r$    r   r   r   r      s        -O-
 $7"7K- - [-  &  &  &D* * *,$ $ $$ $ $ $ $r   r   )r!   r.   r   r   r   r   r   r	   errorsr
   r   r   r   r   r   r;   r   r   <module>r=      s             
         
             b$ b$ b$ b$ b$ b$ b$ b$ b$ b$r   