o
    {Zh
                     @   sb   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 de j	Z
G dd de
ZdS )    N)
exceptions)
GetRequestGetResponsec                   @   s8   e Zd ZejdefddZejdedefddZ	dS )WebAuthnHandlerreturnc                 C      t d)z0Check whether this WebAuthn handler is availablez'is_available method must be implementedNotImplementedErrorself r   U/var/www/html/lang_env/lib/python3.10/site-packages/google/oauth2/webauthn_handler.pyis_available      zWebAuthnHandler.is_availableget_requestc                 C   r   )zWebAuthn get (assertion)zget method must be implementedr   )r   r   r   r   r   get   r   zWebAuthnHandler.getN)
__name__
__module____qualname__abcabstractmethodboolr   r   r   r   r   r   r   r   r   
   s
    r   c                   @   sX   e Zd ZdZdZdefddZdedefddZ	d	e
d
e
de
fddZde
fd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]
    ZGOOGLE_AUTH_WEBAUTHN_PLUGINr   c                 C   s$   z|    W dS  ty   Y dS w )NFT)_find_plugin	Exceptionr
   r   r   r   r   '   s   
zPluginHandler.is_availabler   c                 C   s&   |  }|  }| ||}t|S )N)to_jsonr   _call_pluginr   	from_json)r   r   Zrequest_jsoncmdZresponse_jsonr   r   r   r   /   s   
zPluginHandler.getr   
input_jsonc           
      C   s   t |}td|}||  }tj|g|ddd}|jd d }td|d }|jdd  }	|t |	krAt	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   ZMalformedErrorformatdecode)
r   r   r   Zinput_lengthZlength_bytes_lerequestZprocess_resultZresponse_len_leZresponse_lenresponser   r   r   r   5   s    
zPluginHandler._call_pluginc                 C   s,   t jtj}|d u rtdtj|S )Nz{} env var is not set)osenvironr   r   _ENV_VARr   ZInvalidResourcer,   )r   Z
plugin_cmdr   r   r   r   L   s   
zPluginHandler._find_pluginN)r   r   r   __doc__r2   r   r   r   r   r   strr   r   r   r   r   r   r      s    r   )r   r0   r%   r(   Zgoogle.authr   Zgoogle.oauth2.webauthn_typesr   r   ABCr   r   r   r   r   r   <module>   s    