U
    #FZh
                     @   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                   @   s6   e Zd ZejedddZejeedddZ	dS )WebAuthnHandlerreturnc                 C   s   t ddS )z0Check whether this WebAuthn handler is availablez'is_available method must be implementedNNotImplementedErrorself r   e/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/google/oauth2/webauthn_handler.pyis_available   s    zWebAuthnHandler.is_availableget_requestr   c                 C   s   t ddS )zWebAuthn get (assertion)zget method must be implementedNr   )r   r   r   r   r   get   s    zWebAuthnHandler.getN)
__name__
__module____qualname__abcabstractmethodboolr   r   r   r   r   r   r   r   r   
   s   r   c                   @   sR   e Zd ZdZdZedddZeedddZ	e
e
e
d	d
dZe
d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 n tk
r"   Y dS X dS d S )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.get)r   
input_jsonr   c           
      C   s   t |}td|}||  }tj|g|ddd}|jd d }td|d }|jdd  }	|t |	krt	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 k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   