o
    ýÞh·
  ã                   @   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   ú^/var/www/html/premium_crap/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    