o
    ~j6h
                     @   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   m/var/www/html/chefvision.cloud.itp360.com/venv/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]
    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   request_jsoncmd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   MalformedErrorformatdecode)
r   r    r"   input_lengthlength_bytes_lerequestprocess_resultresponse_len_le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   InvalidResourcer0   )r   
plugin_cmdr   r   r   r   L   s   
zPluginHandler._find_pluginN)r   r   r   __doc__r;   r   r   r   r   r   strr   r   r   r   r   r   r      s    r   )r   r9   r(   r+   google.authr   google.oauth2.webauthn_typesr   r   ABCr   r   r   r   r   r   <module>   s    