o
    l>js                     @  s  d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
mZmZ ddlmZ ddlmZmZmZ dd	lmZmZmZmZmZmZ d
dlmZmZm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%G dd de$Z&G dd dej#Z'edddG dd deZ(edddG dd deZ)dd Z*edddG dd  d eZ+edddG d!d" d"eZ,edddG d#d$ d$eZ-d%d& Z.d'd( Z/G d)d* d*e'Z0edddG d+d, d,eZ1edddG d-d. d.eZ2G d/d0 d0e'Z3G d1d2 d2e'Z4G d3d4 d4e'Z5G d5d6 d6e'Z6G d7d8 d8e'Z7edddG d9d: d:eZ8G d;d< d<e'Z9edddG d=d> d>eZ:edddG d?d@ d@eZ;edddG dAdB dBeZ<G dCdD dDe'Z=edddG dEdF dFeZ>edddG dGdH dHeZ?edddG dIdJ dJeZ@edddG dKdL dLeZAedddG dMdN dNeZBG dOdP dPe'ZCe0 e3 e4 e5 e6 e9 gZDdS )Q    )annotationsN)	dataclass)Enumunique)AnyMappingSequencecast   )cbor)_JsonDataObjectsha256websafe_encode)AuthenticatorSelectionCriteria"PublicKeyCredentialCreationOptionsPublicKeyCredentialDescriptor!PublicKeyCredentialRequestOptionsResidentKeyRequirementUserVerificationRequirement   )AssertionResponseAttestationResponseCtap2)
LargeBlobs)	ClientPinPinProtocolc                   @  s(   e Zd ZdZedddfdd	d
ZdS )ExtensionProcessorzBase class for CTAP2 extension processing.

    See: :class:`RegistrationExtensionProcessor` and
    :class:`AuthenticationExtensionProcessor`.
    r   NpermissionsClientPin.PERMISSIONinputsdict[str, Any] | Noneoutputsc                 C  s   || _ || _|| _d S N)r   _inputs_outputs)selfr   r   r!    r&   K/home/thesage/.local/lib/python3.10/site-packages/fido2/ctap2/extensions.py__init__9   s   
zExtensionProcessor.__init__)r   r   r   r    r!   r    )__name__
__module____qualname____doc__r   
PERMISSIONr(   r&   r&   r&   r'   r   2   s    r   c                   @  s$   e Zd ZdZdddZdd
dZdS )RegistrationExtensionProcessora  Processing state for a CTAP2 extension, for single use.

    The ExtensionProcessor holds state and logic for client processing of an extension,
    for a registration (MakeCredential) call.

    :param permissions: PinUvAuthToken permissions required by the extension.
    :param inputs: Default authenticator inputs, if prepare_inputs is not overridden.
    :param outputs: Default client outputs, if prepare_outputs is not overridden.
    	pin_tokenbytes | Nonereturnr    c                 C     | j S zLPrepare authenticator extension inputs, to be passed to the Authenenticator.r#   r%   r/   r&   r&   r'   prepare_inputsO   s   z-RegistrationExtensionProcessor.prepare_inputsresponser   c                 C  r2   z?Prepare client extension outputs, to be returned to the caller.r$   r%   r7   r/   r&   r&   r'   prepare_outputsS      z.RegistrationExtensionProcessor.prepare_outputsN)r/   r0   r1   r    )r7   r   r/   r0   r1   r    r)   r*   r+   r,   r6   r;   r&   r&   r&   r'   r.   D   s    

r.   c                   @  s$   e Zd ZdZddd	ZdddZdS ) AuthenticationExtensionProcessora  Processing state for a CTAP2 extension, for single use.

    The ExtensionProcessor holds state and logic for client processing of an extension,
    for an authentication (GetAssertion) call.

    :param permissions: PinUvAuthToken permissions required by the extension.
    :param inputs: Default authenticator inputs, if prepare_inputs is not overridden.
    :param outputs: Default client outputs, if prepare_outputs is not overridden.
    selected$PublicKeyCredentialDescriptor | Noner/   r0   r1   r    c                 C  r2   r3   r4   )r%   r?   r/   r&   r&   r'   r6   g   r<   z/AuthenticationExtensionProcessor.prepare_inputsr7   r   c                 C  r2   r8   r9   r:   r&   r&   r'   r;   o   r<   z0AuthenticationExtensionProcessor.prepare_outputsN)r?   r@   r/   r0   r1   r    )r7   r   r/   r0   r1   r    r=   r&   r&   r&   r'   r>   \   s    

r>   c                   @  s4   e Zd ZdZejdddZdddZdddZdS )Ctap2Extensiona'  Base class for CTAP2 extensions.

    As of python-fido2 1.2 these instances can be used for multiple requests and
    should be invoked via the make_credential and get_assertion methods.
    Subclasses are instantiated for a single request, if the Authenticator supports
    the extension.
    ctapr   r1   boolc                 C     dS )z?Whether or not the extension is supported by the authenticator.Nr&   r%   rB   r&   r&   r'   is_supported   s    zCtap2Extension.is_supportedoptionsr   pin_protocolPinProtocol | None%RegistrationExtensionProcessor | Nonec                 C  rD   )z3Start client extension processing for registration.Nr&   r%   rB   rG   rH   r&   r&   r'   make_credential      zCtap2Extension.make_credentialr   'AuthenticationExtensionProcessor | Nonec                 C  rD   )z5Start client extension processing for authentication.Nr&   rK   r&   r&   r'   get_assertion   rM   zCtap2Extension.get_assertionN)rB   r   r1   rC   )rB   r   rG   r   rH   rI   r1   rJ   )rB   r   rG   r   rH   rI   r1   rN   )	r)   r*   r+   r,   abcabstractmethodrF   rL   rO   r&   r&   r&   r'   rA   x   s    
	rA   FT)eqfrozenc                   @  &   e Zd ZU dZded< dZded< dS )HMACGetSecretInputzClient inputs for hmac-secret.bytessalt1Nr0   salt2)r)   r*   r+   r,   __annotations__rX   r&   r&   r&   r'   rU         
 rU   c                   @  rT   )HMACGetSecretOutputzClient outputs for hmac-secret.rV   output1Nr0   output2)r)   r*   r+   r,   rY   r]   r&   r&   r&   r'   r[      rZ   r[   c                 C  s   t d|  S )Ns   WebAuthn PRF )r   )secretr&   r&   r'   	_prf_salt   s   r_   c                   @  rT   ) AuthenticatorExtensionsPRFValueszSalt values for use with prf.rV   firstNr0   second)r)   r*   r+   r,   rY   rb   r&   r&   r&   r'   r`      rZ   r`   c                   @  *   e Zd ZU dZdZded< dZded< dS ) AuthenticatorExtensionsPRFInputszClient inputs for prf.N'AuthenticatorExtensionsPRFValues | Noneevalz5Mapping[str, AuthenticatorExtensionsPRFValues] | Noneeval_by_credential)r)   r*   r+   r,   rf   rY   rg   r&   r&   r&   r'   rd         
 rd   c                   @  rc   )!AuthenticatorExtensionsPRFOutputszClient outputs for prf.Nbool | Noneenabledre   results)r)   r*   r+   r,   rk   rY   rl   r&   r&   r&   r'   ri      rh   ri   c           	      C  s   |rE|j }|j}|r/| stddd | D }||s td|r/t|j}||v r/|| }|s3d S t|j|jd urAt|jndf}n|rP|j	|j
pMdf}nd S t|d tjkrh|d rlt|d tjksltd|S )	Nz+evalByCredentials requires allowCredentialsc                 S     h | ]}t |jqS r&   r   id.0cr&   r&   r'   	<setcomp>       z&_hmac_prepare_salts.<locals>.<setcomp>z&evalByCredentials contains invalid key    r   r   zInvalid salt length)rf   rg   
ValueError
issupersetr   ro   r_   ra   rb   rW   rX   lenHmacSecretExtensionSALT_LEN)	
allow_listr?   prfhmacsecretsby_credsidskeysaltsr&   r&   r'   _hmac_prepare_salts   s6   

r   c                 C  s   |r	|d t j nd }|r|t jd  nd }|r-t| |r!t||nd d}|r+d|iS d S i }| d ur7| |d< |r@t|||d< |pCd S )N)rk   rl   r|   hmacCreateSecrethmacGetSecret)ry   rz   ri   r`   r[   )rk   	decryptedr|   r\   r]   resultr!   r&   r&   r'   _hmac_format_outputs   s   r   c                   @  s>   e Zd ZdZdZdZdZdddZdd	 Zd
d Z	dd Z
dS )ry   a  
    Implements the Pseudo-random function (prf) and the hmac-secret CTAP2 extensions.

    The hmac-secret extension is not directly available to clients by default, instead
    the prf extension is used.

    https://www.w3.org/TR/webauthn-3/#prf-extension

    https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-hmac-secret-extension

    :param allow_hmac_secret: Set to True to allow hmac-secret, in addition to prf.
    zhmac-secretzhmac-secret-mc    Fc                 C  s
   || _ d S r"   )_allow_hmac_secret)r%   allow_hmac_secretr&   r&   r'   r(        
zHmacSecretExtension.__init__c                 C     | j |jjv S r"   NAMEinfo
extensionsrE   r&   r&   r'   rF        z HmacSecretExtension.is_supportedc                   s(  |j pi }|dd u| jo|ddu }r| |rs!|rtjdi d | j|jj v r~t	t
td B |d}|rKt	t
td B |dnd }td d ||}|r~t|}	|	 \}
|d |d  }|}|
||jd tj< G  fdd	d	t}| S d S d S d S )
Nr|   r   Tr   r   r   r   r
         c                      s(   e Zd Z fddZfddZdS )z6HmacSecretExtension.make_credential.<locals>.Processorc                   s    S r"   r&   r5   r   r&   r'   r6   7  s   zEHmacSecretExtension.make_credential.<locals>.Processor.prepare_inputsc                   sJ   |j jpi }|tjd}|tj}|rr |nd }t||S )NF)	auth_datar   getry   r   MC_NAMEdecryptr   )r%   r7   r/   r   rk   valuer   rH   r|   shared_secretr&   r'   r;   :  s   zFHmacSecretExtension.make_credential.<locals>.Processor.prepare_outputsNr)   r*   r+   r6   r;   r&   r   rH   r|   r   r&   r'   	Processor6  s    r   )r   r   r   rF   ry   r   r   r   rd   	from_dictr	   r   rU   r   r   _get_shared_secretencryptauthenticateVERSIONr.   )r%   rB   rG   rH   c_inputsr}   	prf_salts
hmac_saltsr   
client_pinkey_agreementsalt_enc	salt_authr   r&   r   r'   rL     s<   


z#HmacSecretExtension.make_credentialc                   s   j pi }tttd B |d| jr"tttd B |dnd  rL| |rNs/ rPt	|}|
 \G  fdddt}| S d S d S d S )Nr|   r   c                      s2   e Zd Z fddZfddZdS )z5HmacSecretExtension.get_assertion.<locals>.Processingc                   sR   t j| }|sd S |d |d  }|}tj||jdiS )Nr   r   r   )r   allow_credentialsr   r   ry   r   r   )r%   r?   r/   r   r   r   r}   r   rG   rH   r|   r   r&   r'   r6   Y  s   
zDHmacSecretExtension.get_assertion.<locals>.Processing.prepare_inputsc                   s8   |j jpi }|tj}|r |nd }td |S r"   )r   r   r   ry   r   r   r   )r%   r7   r/   r   r   r   r   r&   r'   r;   l  s
   zEHmacSecretExtension.get_assertion.<locals>.Processing.prepare_outputsNr   r&   r   r&   r'   
ProcessingX  s    r   )r   rd   r   r	   r   r   r   rU   rF   r   r   r>   )r%   rB   rG   rH   r   r   r   r&   r   r'   rO   G  s    

z!HmacSecretExtension.get_assertionN)F)r)   r*   r+   r,   r   r   rz   r(   rF   rL   rO   r&   r&   r&   r'   ry      s    
0ry   c                   @  s6   e Zd ZU dZdZded< dZded< dZded< dS )	&AuthenticatorExtensionsLargeBlobInputszClient inputs for largeBlob.N
str | Nonesupportrj   readr0   write)r)   r*   r+   r,   r   rY   r   r   r&   r&   r&   r'   r   w  
   
 r   c                   @  s6   e Zd ZU dZdZded< dZded< dZded< dS )'AuthenticatorExtensionsLargeBlobOutputszClient outputs for largeBlob.Nrj   	supportedr0   blobwritten)r)   r*   r+   r,   r   rY   r   r   r&   r&   r&   r'   r     r   r   c                   @  ,   e Zd ZdZdZdd Zdd Zdd Zd	S )
LargeBlobExtensionz
    Implements the Large Blob storage (largeBlob) WebAuthn extension.

    https://www.w3.org/TR/webauthn-3/#sctn-large-blob-extension
    largeBlobKeyc                 C  s   | j |jjv o|jjddS )N
largeBlobsF)r   r   r   rG   r   rE   r&   r&   r'   rF     s   zLargeBlobExtension.is_supportedc                 C  sr   |j pi }tttd B |d}|r7|js|jrtd|j	dkr,| 
|s,tdG dd dt}| S d S )N	largeBlobInvalid set of parametersrequired1Authenticator does not support large blob storagec                   @  s   e Zd Zdd Zdd ZdS )z5LargeBlobExtension.make_credential.<locals>.Processorc                 S  s
   t jdiS NT)r   r   r5   r&   r&   r'   r6     r   zDLargeBlobExtension.make_credential.<locals>.Processor.prepare_inputsc                 S  s   dt |jd udiS )Nr   )r   )r   large_blob_keyr:   r&   r&   r'   r;     s   zELargeBlobExtension.make_credential.<locals>.Processor.prepare_outputsNr   r&   r&   r&   r'   r     s    r   )r   r   r   r	   r   r   r   r   rv   r   rF   r.   )r%   rB   rG   rH   r   datar   r&   r&   r'   rL     s   
z"LargeBlobExtension.make_credentialc                   s   |j pi }tttd B |drIjsjr!jr!t	d| 
 s*t	dG  fdddt}|jr>tjjntdtjdidS d S )	Nr   r   r   c                      s   e Zd Z fddZdS )z3LargeBlobExtension.get_assertion.<locals>.Processorc                   sr   d usJ |j }|r5jrt }||}dt|diS jr7t |}||j dtddiS d S d S )Nr   )r   T)r   )r   r   r   get_blobr   r   put_blob)r%   r7   r/   blob_keylarge_blobsr   rB   r   rH   r&   r'   r;     s&   
	zCLargeBlobExtension.get_assertion.<locals>.Processor.prepare_outputsN)r)   r*   r+   r;   r&   r   r&   r'   r     s    r   r   Tr   )r   r   r   r	   r   r   r   r   r   rv   rF   r>   r   r-   LARGE_BLOB_WRITEr   r   r%   rB   rG   rH   r   r   r&   r   r'   rO     s"   


z LargeBlobExtension.get_assertionNr)   r*   r+   r,   r   rF   rL   rO   r&   r&   r&   r'   r     s    r   c                   @  r   )
CredBlobExtensionz
    Implements the Credential Blob (credBlob) CTAP2 extension.

    https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-credBlob-extension
    credBlobc                 C  r   r"   r   rE   r&   r&   r'   rF     r   zCredBlobExtension.is_supportedc                 C  s^   |j pi }| |r)|d}|jjd usJ |r+t||jjkr-t| j|idS d S d S d S )Nr   r   )r   rF   r   r   max_cred_blob_lengthrx   r.   r   )r%   rB   rG   rH   r   r   r&   r&   r'   rL     s   


z!CredBlobExtension.make_credentialc                 C  s:   |j pi }| |r|ddu rt| jdidS d S d S )NgetCredBlobTr   )r   rF   r   r>   r   r%   rB   rG   rH   r   r&   r&   r'   rO     s   
zCredBlobExtension.get_assertionNr   r&   r&   r&   r'   r     s    r   c                   @  s8   e Zd ZdZeG dd deZdZdd Zdd Z	d	S )
CredProtectExtensionz
    Implements the Credential Protection CTAP2 extension.

    https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-credProtect-extension
    c                   @  s&   e Zd ZdZdZdZeddd	Zd
S )zCredProtectExtension.POLICYuserVerificationOptional,userVerificationOptionalWithCredentialIDListuserVerificationRequiredpolicystrr1   intc                 C  s   t | | |d S )Nr   )listindex)clsr   r&   r&   r'   str2int  s   z#CredProtectExtension.POLICY.str2intN)r   r   r1   r   )r)   r*   r+   OPTIONALOPTIONAL_WITH_LISTREQUIREDclassmethodr   r&   r&   r&   r'   POLICY  s    r   credProtectc                 C  r   r"   r   rE   r&   r&   r'   rF     r   z!CredProtectExtension.is_supportedc                 C  sb   |j pi }|d}|r/tj|}|dd}|r'| |s'|dkr'tdt| j|idS d S )NcredentialProtectionPolicy!enforceCredentialProtectionPolicyFr   z4Authenticator does not support Credential Protectionr   )	r   r   r   r   r   rF   rv   r.   r   )r%   rB   rG   rH   r   r   r   enforcer&   r&   r'   rL   
  s   

z$CredProtectExtension.make_credentialN)
r)   r*   r+   r,   r   r   r   r   rF   rL   r&   r&   r&   r'   r     s    	r   c                   @  $   e Zd ZdZdZdd Zdd ZdS )MinPinLengthExtensionz
    Implements the Minimum PIN Length (minPinLength) CTAP2 extension.

    https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-minpinlength-extension
    minPinLengthc                 C  s   d|j jv S )NsetMinPINLength)r   rG   rE   r&   r&   r'   rF     s   z"MinPinLengthExtension.is_supportedc                 C  <   |j pi }| |r|| jdu rt| jdidS d S d S NTr   r   rF   r   r   r.   r   r&   r&   r'   rL   #     
z%MinPinLengthExtension.make_credentialNr)   r*   r+   r,   r   rF   rL   r&   r&   r&   r'   r     
    r   c                   @  r   )PinComplexityPolicyExtensionz
    Implements the PIN Complexity Policy (pinComplexityPolicy) CTAP2 extension.

    https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-minpinlength-extension
    pinComplexityPolicyc                 C  r   r"   r   rE   r&   r&   r'   rF   2  r   z)PinComplexityPolicyExtension.is_supportedc                 C  r   r   r   r   r&   r&   r'   rL   5  r   z,PinComplexityPolicyExtension.make_credentialNr   r&   r&   r&   r'   r   )  s
    r   c                   @  s   e Zd ZU dZdZded< dS )CredentialPropertiesOutputzClient outputs for credProps.Nrj   rk)r)   r*   r+   r,   r   rY   r&   r&   r&   r'   r   ;  s   
 r   c                   @  r   )CredPropsExtensionz
    Implements the Credential Properties (credProps) WebAuthn extension.

    https://www.w3.org/TR/webauthn-3/#sctn-authenticator-credential-properties-extension
    	credPropsc                 C  rD   r   r&   rE   r&   r&   r'   rF   K  s   zCredPropsExtension.is_supportedc                 C  sf   |j pi }|| jdu r1|jpt }|jtjkp%|jtjko%|j	j
d}t| jt|didS d S )NTr   )r   )r!   )r   r   r   authenticator_selectionr   resident_keyr   r   	PREFERREDr   rG   r.   r   )r%   rB   rG   rH   r   	selectionr   r&   r&   r'   rL   O  s   

z"CredPropsExtension.make_credentialNr   r&   r&   r&   r'   r   B  r   r   c                   @  s   e Zd ZU ded< ded< dS )PaymentCurrencyAmountr   currencyr   Nr)   r*   r+   rY   r&   r&   r&   r'   r   _  s   
 r   c                   @  s*   e Zd ZU ded< ded< dZded< dS )PaymentCredentialInstrumentr   display_nameiconTrC   icon_must_be_shownN)r)   r*   r+   rY   r   r&   r&   r&   r'   r   e     
 r   c                   @  sf   e Zd ZU dZdZded< dZded< dZded< dZded< dZ	ded	< dZ
d
ed< dZded< dS )%AuthenticationExtensionsPaymentInputszClient inputs for payment.Nrj   
is_paymentr   rp_id
top_origin
payee_namepayee_originzPaymentCurrencyAmount | Nonetotalz"PaymentCredentialInstrument | None
instrument)r)   r*   r+   r,   r  rY   r  r  r  r  r  r	  r&   r&   r&   r'   r  l  s   
 r  c                   @  r   )
ThirdPartyPaymentExtensiona]  
    Implements the Third Party Payment (thirdPartyPayment) CTAP2.2 extension.

    https://fidoalliance.org/specs/fido-v2.2-ps-20250228/fido-client-to-authenticator-protocol-v2.2-ps-20250228.html#sctn-thirdPartyPayment-extension

    Note that most of the processing for the WebAuthn extension needs to be done by the
    client, see:
    https://www.w3.org/TR/secure-payment-confirmation/#sctn-collectedclientpaymentdata-dictionary

    As such, this extension is not included in the default extensions list, and should
    not be used without a client that supports the WebAuthn payment extension.
    thirdPartyPaymentc                 C  r   r"   r   rE   r&   r&   r'   rF     r   z'ThirdPartyPaymentExtension.is_supportedc                 C  T   |j pi }tttd B |d}| |r$|r&|jr(t| j	didS d S d S d S NpaymentTr   )
r   r  r   r	   r   r   rF   r  r.   r   r%   rB   rG   rH   r   r   r&   r&   r'   rL        
z*ThirdPartyPaymentExtension.make_credentialc                 C  r  r  )
r   r  r   r	   r   r   rF   r  r>   r   r  r&   r&   r'   rO     r  z(ThirdPartyPaymentExtension.get_assertionNr   r&   r&   r&   r'   r
  y  s    r
  c                   @  s   e Zd ZU ded< dS )_SignGenerateKeyInputszSequence[int]
algorithmsNr   r&   r&   r&   r'   r    s   
 r  c                   @  s*   e Zd ZU ded< ded< dZded< dS )_SignSignInputsrV   
key_handletbsNr0   additional_args)r)   r*   r+   rY   r  r&   r&   r&   r'   r    r  r  c                   @  &   e Zd ZU dZded< dZded< dS )_SignInputsNz_SignGenerateKeyInputs | Nonegenerate_keyz$Mapping[str, _SignSignInputs] | Nonesign_by_credential)r)   r*   r+   r  rY   r  r&   r&   r&   r'   r       
 r  c                   @  s.   e Zd ZU ded< ded< ded< ded< dS )_SignGeneratedKeyrV   r  
public_keyr   	algorithmattestation_objectNr   r&   r&   r&   r'   r    s
   
 r  c                   @  r  )_SignOutputsNz_SignGeneratedKey | Nonegenerated_keyr0   	signature)r)   r*   r+   r!  rY   r"  r&   r&   r&   r'   r     r  r   c                   @  r   )
PreviewSignExtensiona  
    WARNING: This extension is currently in DRAFT.
    It is to be considered experimental, and NOT part of the stable API of this library.

    Implements version 4-SNAPSHOT-2025-08-21T15:00 of the sign CTAP2 extension.

    https://github.com/yubicolabs/webauthn-sign-extension
    previewSignc                 C  r   r"   r   rE   r&   r&   r'   rF     r   z!PreviewSignExtension.is_supportedc                   s^   j pi }t|| j  r| |sd S  js js!tdG  fdddt	}| S )NInvalid inputsc                      "   e Zd Z fddZdd ZdS )z7PreviewSignExtension.make_credential.<locals>.Processorc                   s<    j }jpt }|jtjkrdnd}|j|d}tj|iS )N   r   )r   r   )	r  r   r   user_verificationr   r   r  r#  r   )r%   r/   gkr   flagsr!   r   rG   r&   r'   r6     s   

zFPreviewSignExtension.make_credential.<locals>.Processor.prepare_inputsc           
      S  s   |j jpi }|tj}|sd S |jtj d }ttt	t
|}|j j}|d us-J |j}|j}	tjtt|t
|	|d|ddiS )N   r   )r  r  r  r  )r!  )r   r   r   r#  r   unsigned_extension_outputsr   r   r	   r   r   decodecredential_datacredential_idr  r   r  encode)
r%   r7   r/   r   r   att_obj_bytesatt_obj	cred_datakhpkr&   r&   r'   r;     s2   zGPreviewSignExtension.make_credential.<locals>.Processor.prepare_outputsNr   r&   r+  r&   r'   r     s    r   )
r   r  r   r   r   rF   r  r  rv   r.   r   r&   r+  r'   rL     s   
,z$PreviewSignExtension.make_credentialc                   s^   j pi }t|| j  r| |sd S  jr jr!tdG  fdddt	}| S )Nr%  c                      r&  )z5PreviewSignExtension.get_assertion.<locals>.Processorc                   sr    j }j}|r
|stddd |D }||rtd|t|j }|j|jd}|jr4|j|d< t	j
|iS )Nzsign requires allowCredentialsc                 S  rm   r&   rn   rp   r&   r&   r'   rs     rt   zWPreviewSignExtension.get_assertion.<locals>.Processor.prepare_inputs.<locals>.<setcomp>z"keyHandleByCredential is not valid)r
      r,  )r  r   rv   
differencer   ro   r  r  r  r#  r   )r%   r?   r/   r   r{   r   cred_inputsauthenticator_inputr+  r&   r'   r6     s   


zDPreviewSignExtension.get_assertion.<locals>.Processor.prepare_inputsc                 S  s4   |j jpi }|tj}|rtjt|d diS d S )Nr7  )r"  )r   r   r   r#  r   r   )r%   r7   r/   r   r   r&   r&   r'   r;   "  s
   zEPreviewSignExtension.get_assertion.<locals>.Processor.prepare_outputsNr   r&   r+  r&   r'   r     s    r   )
r   r  r   r   r   rF   r  r  rv   r>   r   r&   r+  r'   rO     s   
z"PreviewSignExtension.get_assertionNr   r&   r&   r&   r'   r#    s    	7r#  )E
__future__r   rP   dataclassesr   enumr   r   typingr   r   r   r	    r   utilsr   r   r   webauthnr   r   r   r   r   r   baser   r   r   r   r   pinr   r   ABCr   r.   r>   rA   rU   r[   r_   r`   rd   ri   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r  r   r#  _DEFAULT_EXTENSIONSr&   r&   r&   r'   <module>   s    
 



%
x
Q"




$



o