
    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y)    N)
exceptions)
GetRequestGetResponsec                   d    e Zd Zej                  defd       Zej                  dedefd       Z	y)WebAuthnHandlerreturnc                     t        d      )z0Check whether this WebAuthn handler is availablez'is_available method must be implementedNotImplementedErrorselfs    S/var/www/openai/venv/lib/python3.12/site-packages/google/oauth2/webauthn_handler.pyis_availablezWebAuthnHandler.is_available   s     ""K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Cr   N)
__name__
__module____qualname__abcabstractmethodboolr   r   r   r    r   r   r   r   
   sP    Md M M 	Dz Dk D Dr   r   c                   P    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y)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                 D    	 | j                          y# t        $ r Y yw xY w)NTF)_find_plugin	Exceptionr   s    r   r   zPluginHandler.is_available'   s,    	   		s    	r   c                     |j                         }| j                         }| j                  ||      }t        j                  |      S )N)to_jsonr   _call_pluginr   	from_json)r   r   request_jsoncmdresponse_jsons        r   r   zPluginHandler.get/   sA    "**,!))#|<$$]33r   r&   
input_jsonc                    t        |      }t        j                  d|      }||j                         z   }t	        j
                  |g|dd      }|j                  d d }t        j                  d|      d   }|j                  dd  }	|t        |	      k7  r.t        j                  dj                  |t        |	                  |	j                         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!J$5$5$77 $ET

 )//3}}T?;A>!((,3x=(++BII #h- 
   r   c                     t         j                  j                  t        j                        }|2t        j                  dj                  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    ZZ^^M$:$:;
,,'..}/E/EF  r   N)r   r   r   __doc__rC   r   r   r   r   r   strr#   r   r   r   r   r   r      sS     -Hd 4z 4k 4! ! ! !.c r   r   )r   rA   r/   r2   google.authr   google.oauth2.webauthn_typesr   r   ABCr   r   r   r   r   <module>rK      s5    
 	   " @	Dcgg 	D<O <r   