
    @wj7                         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    \/root/dashboard-youtube/.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 request 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                 F   t        |      }t        j                  d|      }||j                         z   }t	        j
                  |g|d      }|j                  dk7  r|j                  }t        |      dk\  r0t        j                  d|d d       d   t        |      dz
  k(  r|dd  }dj                  ||j                  |j                  d      j                         |j                  j                  d      j                               }t        j                  |      |j                  d d }	t        j                  d|	      d   }
|j                  dd  }|
t        |      k7  r.t        j                  d	j                  |
t        |                  |j                         S )
Nz<IT)inputcapture_outputr      zDCommand '{}' returned non-zero exit status {}.
Stdout: {}
Stderr: {}replace)errorsz0Plugin response length {} does not match data {})lenstructpackencode
subprocessrun
returncodestdoutunpackformatdecodestripstderrr   GoogleAuthErrorMalformedError)r   r&   r(   input_lengthlength_bytes_lerequestprocess_resultstdout_bytes	error_msgresponse_len_leresponse_lenresponses               r   r#   zPluginHandler._call_plugin5   s   : ++dL9!J$5$5$77 $WTR$$))00LL!Q&MM$Ra(89!<L@QTU@UU+AB/`gg))##9#5;;=%%,,I,>DDF	I ,,Y77 )//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   InvalidResourcer8   )r   
plugin_cmds     r   r   zPluginHandler._find_plugin[   sO    ZZ^^M$:$:;
,,'..}/E/EF  r   N)r   r   r   __doc__rJ   r   r   r   r   r   strr#   r   r   r   r   r   r      sT     -Hd 4z 4k 4$! $! $! $!Lc r   r   )r   rH   r0   r3   google.authr   google.oauth2.webauthn_typesr   r   ABCr   r   r   r   r   <module>rR      s7    
 	   " @	Dcgg 	DKO Kr   