
    )Jf%                         d Z g dZddlmZ ddlZdZdZdZdZ ej	        d	          Z
 G d
 de          Zee_         G d de          Zee_        dS )zAn implementation of the OpenID Provider Authentication Policy
Extension 1.0

@see: http://openid.net/developers/specs/

@since: 2.1.0
)RequestResponsens_uriAUTH_PHISHING_RESISTANTAUTH_MULTI_FACTORAUTH_MULTI_FACTOR_PHYSICAL    )	ExtensionNz+http://specs.openid.net/extensions/pape/1.0zEhttp://schemas.openid.net/pape/policies/2007/06/multi-factor-physicalz<http://schemas.openid.net/pape/policies/2007/06/multi-factorzBhttp://schemas.openid.net/pape/policies/2007/06/phishing-resistantz$^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$c                   b     e Zd ZdZdZd fd	Zd Zd Zd Zd Z	 e
e	          Z	d	 Zd
 Z xZS )r   a  A Provider Authentication Policy request, sent from a relying
    party to a provider

    @ivar preferred_auth_policies: The authentication policies that
        the relying party prefers
    @type preferred_auth_policies: [str]

    @ivar max_auth_age: The maximum time, in seconds, that the relying
        party wants to allow to have elapsed before the user must
        re-authenticate
    @type max_auth_age: int or NoneType
    papeNc                 z    t          t          |                                            |sg }|| _        || _        d S N)superr   __init__preferred_auth_policiesmax_auth_age)selfr   r   	__class__s      `/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/extensions/draft/pape2.pyr   zRequest.__init__1   sC    gt%%'''& 	)&(#'>$(    c                 <    t          | j        p| j        d u          S r   )boolr   r   )r   s    r   __bool__zRequest.__bool__9   s)    D0 2%T13 3 	3r   c                 P    || j         vr| j                             |           dS dS )a  Add an acceptable authentication policy URI to this request

        This method is intended to be used by the relying party to add
        acceptable authentication types to the request.

        @param policy_uri: The identifier for the preferred type of
            authentication.
        @see: http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-01.html#auth_policies
        N)r   appendr   
policy_uris     r   addPolicyURIzRequest.addPolicyURI=   s7     T999(//
;;;;; :9r   c                 z    dd                     | j                  i}| j        t          | j                  |d<   |S )/@see: C{L{Extension.getExtensionArgs}}
        r    Nr   )joinr   r   strr   ns_argss     r   getExtensionArgszRequest.getExtensionArgsJ   sD     &sxx0L'M'M
 (&)$*;&<&<GN#r   c                      |             }|j                             |j                  }|i k    rdS |                    |           |S )zaInstantiate a Request object from the arguments in a
        C{checkid_*} OpenID message
        N)messagegetArgsr   parseExtensionArgs)clsrequestr   argss       r   fromOpenIDRequestzRequest.fromOpenIDRequestV   sM     suu&&t{332::4%%%r   c                    g | _         |                    d          }|rat          |t                    rt	          |d          }|                    d          D ]%}|| j         vr| j                             |           &|                    d          }d| _        |r(	 t          |          | _        dS # t          $ r Y dS w xY wdS )a  Set the state of this request to be that expressed in these
        PAPE arguments

        @param args: The PAPE arguments without a namespace

        @rtype: None

        @raises ValueError: When the max_auth_age is not parseable as
            an integer
        r   zutf-8)encodingr    r   N)
r   get
isinstancebytesr"   splitr   r   int
ValueError)r   r,   policies_strurimax_auth_age_strs        r   r)   zRequest.parseExtensionArgse   s     (*$xx 9:: 	=,.. C"<'BBB#))#.. = =d:::077<<<  88N33  	$'(8$9$9!!!   	 	s   B5 5
CCc                 P    t          t          | j        j        |                    S )a  Given a list of authentication policy URIs that a provider
        supports, this method returns the subsequence of those types
        that are preferred by the relying party.

        @param supported_types: A sequence of authentication policy
            type URIs that are supported by a provider

        @returns: The sub-sequence of the supported types that are
            preferred by the relying party. This list will be ordered
            in the order that the types appear in the supported_types
            sequence, and may be empty if the provider does not prefer
            any of the supported authentication types.

        @returntype: [str]
        )listfilterr   __contains__)r   supported_typess     r   preferredTypeszRequest.preferredTypes   s,      4/<oNNP P 	Pr   )NN)__name__
__module____qualname____doc__ns_aliasr   r   r   r%   r-   classmethodr)   r>   __classcell__r   s   @r   r   r   !   s          H) ) ) ) ) )3 3 3< < <
 
 
   $$566  BP P P P P P Pr   r   c                   ^     e Zd ZdZdZ	 	 	 d
 fd	Zd Zd ZddZ e	e          Zd	 Z
 xZS )r   z[A Provider Authentication Policy response, sent from a provider
    to a relying party
    r   Nc                     t          t          |                                            |r|| _        ng | _        || _        || _        d S r   )r   r   r   auth_policies	auth_timenist_auth_level)r   rI   rJ   rK   r   s       r   r   zResponse.__init__   sQ     	h&&((( 	$!.D!#D".r   c                 P    || j         vr| j                             |           dS dS )a  Add a authentication policy to this response

        This method is intended to be used by the provider to add a
        policy that the provider conformed to when authenticating the user.

        @param policy_uri: The identifier for the preferred type of
            authentication.
        @see: http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-01.html#auth_policies
        N)rI   r   r   s     r   r   zResponse.addPolicyURI   s7     T///%%j11111 0/r   c                      |             }|                     |j                  }||                    |           |S dS )a9  Create a C{L{Response}} object from a successful OpenID
        library response
        (C{L{openid.consumer.consumer.SuccessResponse}}) response
        message

        @param success_response: A SuccessResponse from consumer.complete()
        @type success_response: C{L{openid.consumer.consumer.SuccessResponse}}

        @rtype: Response or None
        @returns: A provider authentication policy response from the
            data that was supplied with the C{id_res} response or None
            if the provider sent no signed PAPE response arguments.
        N)getSignedNSr   r)   )r*   success_responser   r,   s       r   fromSuccessResponsezResponse.fromSuccessResponse   sL     suu  ++DK88 ##D)))K4r   Fc                    |                     d          }|r |dk    r|                    d          | _        |                     d          }|rP	 t          |          }d|cxk    rdk     r
n n0|| _        n(# t
          $ r |rt          d          d| _        Y nw xY w|                     d	          }|r4t                              |          r	|| _        dS |rt          d
          dS dS )a  Parse the provider authentication policy arguments into the
        internal state of this object

        @param args: unqualified provider authentication policy
            arguments

        @param strict: Whether to raise an exception when bad data is
            encountered

        @returns: None. The data is parsed into the internal fields of
            this object.
        rI   noner    rK   r      Cnist_auth_level must be an integer between zero and four, inclusiveNrJ   #auth_time must be in RFC3339 format)	r0   r3   rI   r4   rK   r5   TIME_VALIDATORmatchrJ   )r   r,   strictr6   nist_level_str
nist_levelrJ   s          r   r)   zResponse.parseExtensionArgs   sP    xx00 	9LF22!-!3!3C!8!8D"344 	66 00
 
&&&&Q&&&&&+5D(  0 0 0 0$34 4 4 ,0D(((0 HH[))	 	H##I.. H!* H !FGGG		H 	HH Hs   A7 7"BBc                    t          | j                  dk    rddi}ndd                    | j                  i}| j        J| j        t	          t          dd                    vrt          d          t          | j                  |d<   | j        8t          
                    | j                  st          d	          | j        |d
<   |S )r   r   rI   rR   r    NrS   rT   rK   rU   rJ   )lenrI   r!   rK   r:   ranger5   r"   rJ   rV   rW   r#   s     r   r%   zResponse.getExtensionArgs  s     t!""a''GG
  $*<!=!=G +#4a+<+<<<  "< = = =),T-A)B)BG%&>%!''77 H !FGGG#'>GK r   )NNN)F)r?   r@   rA   rB   rC   r   r   rP   r)   rD   r%   rE   rF   s   @r   r   r      s          H  $!%/ / / / / /2 2 2  6%H %H %H %HN &+&9::      r   r   )rB   __all__openid.extensionr	   rer   r   r   r   compilerV   r   r    r   r   <module>rc      s       ' & & & & & 					6 L  C  I  BCCvP vP vP vP vPi vP vP vPr } } } } }y } } }@ r   