
    &g
                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ  G d de j	                  Z
 G d de
          ZdS )    N)
exceptions)
GetRequestGetResponsec                   ^    e Zd Zej        defd            Zej        dedefd            Z	dS )WebAuthnHandlerreturnc                      t          d          )z0Check whether this WebAuthn handler is availablez'is_available method must be implementedNotImplementedErrorselfs    P/var/www/api/venv/lib/python3.11/site-packages/google/oauth2/webauthn_handler.pyis_availablezWebAuthnHandler.is_available   s     ""KLLL    get_requestc                      t          d          )zWebAuthn get (assertion)zget method must be implementedr
   )r   r   s     r   getzWebAuthnHandler.get   s     ""BCCCr   N)
__name__
__module____qualname__abcabstractmethodboolr   r   r   r    r   r   r   r   
   s|        Md M M M M 	Dz Dk D D D D D Dr   r   c                   R    e Zd ZdZdZdefdZdedefdZ	de
de
de
fd	Zde
fd
ZdS )PluginHandlera  Offloads WebAuthn get reqeust to a pluggable command-line tool.

    Offloads WebAuthn get to a plugin which takes the form of a
    command-line tool. The command-line tool is configurable via the
    PluginHandler._ENV_VAR environment variable.

    The WebAuthn plugin should implement the following interface:

    Communication occurs over stdin/stdout, and messages are both sent and
    received in the form:

    [4 bytes - payload size (little-endian)][variable bytes - json payload]
    GOOGLE_AUTH_WEBAUTHN_PLUGINr   c                 R    	 |                                   dS # t          $ r Y dS w xY w)NTF)_find_plugin	Exceptionr   s    r   r   zPluginHandler.is_available'   sD    	 4  	 	 	55	s    
&&r   c                     |                                 }|                                 }|                     ||          }t          j        |          S )N)to_jsonr   _call_pluginr   	from_json)r   r   request_jsoncmdresponse_jsons        r   r   zPluginHandler.get/   sJ    "**,,!!))#|<<$]333r   r&   
input_jsonc                    t          |          }t          j        d|          }||                                z   }t	          j        |g|dd          }|j        d d         }t          j        d|          d         }|j        dd          }	|t          |	          k    r5t          j	        d
                    |t          |	                              |	                                S )Nz<IT)inputcapture_outputcheck   r   z0Plugin response length {} does not match data {})lenstructpackencode
subprocessrunstdoutunpackr   MalformedErrorformatdecode)
r   r&   r(   input_lengthlength_bytes_lerequestprocess_resultresponse_len_leresponse_lenresponses
             r   r#   zPluginHandler._call_plugin5   s    : +dL99!J$5$5$7$77 $ET
 
 

 )/3}T?;;A>!(,3x==((+BII #h--   
    r   c                     t           j                            t          j                  }|1t          j        d                    t          j                            |S )Nz{} env var is not set)osenvironr   r   _ENV_VARr   InvalidResourcer7   )r   
plugin_cmds     r   r   zPluginHandler._find_pluginL   sO    Z^^M$:;;
,'..}/EFF   r   N)r   r   r   __doc__rC   r   r   r   r   r   strr#   r   r   r   r   r   r      s          -Hd    4z 4k 4 4 4 4! ! ! ! ! ! !.c      r   r   )r   rA   r/   r2   google.authr   google.oauth2.webauthn_typesr   r   ABCr   r   r   r   r   <module>rK      s    



 				      " " " " " " @ @ @ @ @ @ @ @	D 	D 	D 	D 	Dcg 	D 	D 	D< < < < <O < < < < <r   