
    f%                         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_        y)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                   \     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
    papec                 N    t         t        |           |sg }|| _        || _        y N)superr   __init__preferred_auth_policiesmax_auth_age)selfr   r   	__class__s      X/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/extensions/draft/pape2.pyr   zRequest.__init__1   s)    gt%'&&(#'>$(    c                 L    t        | j                  xs | j                  d u      S r   )boolr   r   )r   s    r   __bool__zRequest.__bool__9   s*    D00 2%%T13 	3r   c                 X    || j                   vr| j                   j                  |       yy)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=   s+     T999((//
; :r   c                     ddj                  | j                        i}| j                  t        | j                        |d<   |S )/@see: C{L{Extension.getExtensionArgs}}
        r    r   )joinr   r   strr   ns_argss     r   getExtensionArgszRequest.getExtensionArgsJ   sG     &sxx0L0L'M
 (&)$*;*;&<GN#r   c                      |        }|j                   j                  |j                        }|i k(  ry|j                  |       |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   s@     u&&t{{32:%r   c                 h   g | _         |j                  d      }|r]t        |t              rt	        |d      }|j                  d      D ],  }|| j                   vs| j                   j                  |       . |j                  d      }d| _        |r	 t        |      | _        yy# t        $ r Y yw xY w)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:,."<'B#))#. =d:::0077<=
  88N3 $'(8$9!   s   B% %	B10B1c                 T    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P 	Pr   )NN)__name__
__module____qualname____doc__ns_aliasr   r   r   r%   r-   classmethodr)   r>   __classcell__r   s   @r   r   r   !   sB     H)3<
 $$56BPr   r   c                   X     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   c                 h    t         t        |           |r|| _        ng | _        || _        || _        y r   )r   r   r   auth_policies	auth_timenist_auth_level)r   rI   rJ   rK   r   s       r   r   zResponse.__init__   s4     	h&(!.D!#D".r   c                 X    || j                   vr| j                   j                  |       yy)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   s+     T///%%j1 0r   c                 r     |        }|j                  |j                        }||j                  |       |S y)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   s?     u  ++DKK8 ##D)Kr   c                    |j                  d      }|r|dk7  r|j                  d      | _        |j                  d      }|r"	 t        |      }d|cxk  rdk  rn n|| _        	 |j                  d	      }|r+t        j                  |      r|| _        y|rt        d
      yy# t
        $ r |rt        d      d| _        Y ^w xY w)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   s     xx0LF2!-!3!3C!8D"346 0
 
&Q&+5D(HH[)	##I.!* !FGG    0$34 4 ,0D(0s   B# #CCc                    t        | j                        dk(  rddi}nddj                  | j                        i}| j                  D| j                  t	        t        dd            vrt        d      t        | j                        |d<   | j                  9t        j                  | j                        st        d      | j                  |d	<   |S )
r   r   rI   rR   r    rS   rT   rK   rU   rJ   )lenrI   r!   rK   r:   ranger5   r"   rJ   rV   rW   r#   s     r   r%   zResponse.getExtensionArgs  s     t!!"a'G
  $*<*<!=G +##4a+<<  "< = =),T-A-A)BG%&>>%!''7 !FGG#'>>GK r   )NNN)F)r?   r@   rA   rB   rC   r   r   rP   r)   rD   r%   rE   rF   s   @r   r   r      sC     H  $!%/26%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vPi vPr }y }@ r   