o
    l>j3                     @  s:  U d Z ddlmZ ddlZddlmZ ejeje	dZ
ee
dTZe Zded< e Zded	< e Zded
< eD ]4Zed ZerKedrLq;edr[eedd  q;edrjeedd  q;ee q;W d   n1 szw   Y  eedd eD B dd eD B ZdddZdddZdS ) a6  
These functions validate RP_ID and APP_ID according to simplified TLD+1 rules,
using a bundled copy of the public suffix list fetched from:

  https://publicsuffix.org/list/public_suffix_list.dat

Advanced APP_ID values pointing to JSON files containing valid facets are not
supported by this implementation.
    )annotationsN)urlparsezpublic_suffix_list.datrbzset[str]_suffix_set_wildcard_set_exception_setutf8z//!   *.   c                 C     h | ]}d | qS )r    ).0wr   r   ?/home/thesage/.local/lib/python3.10/site-packages/fido2/rpid.py	<setcomp>=       r   c                 C  r   )r	   r   )r   er   r   r   r   =   r   domainstrreturnboolc                 C  sD   | t v rdS | tv rdS | dd}t|dkr |d tv r dS dS )zvCheck if a domain is a public suffix per the PSL algorithm.

    https://github.com/publicsuffix/list/wiki/Format
    FT.r
   r   )r   r   splitlenr   )r   partsr   r   r   _is_public_suffixA   s   r   rp_idoriginc                 C  sx   | sdS t |}|j}|jdkr%|j|fdkr%|jdkr#|r#|ds%dS || kr+dS |r:|d|  r:t| s:dS dS )zChecks if a Webauthn RP ID is usable for a given origin.

    :param rp_id: The RP ID to validate.
    :param origin: The origin of the request.
    :return: True if the RP ID is usable by the origin, False if not.
    Fhttps)http	localhostr!   z
.localhostTr   )r   hostnameschemeendswithr   )r   r   urlhostr   r   r   verify_rp_idP   s   
r(   )r   r   r   r   )r   r   r   r   r   r   )__doc__
__future__r   osurllib.parser   pathjoindirname__file__	tld_fnameopenfsetr   __annotations__r   r   _linedecodestrip_entry
startswithaddsortedsuffixesr   r(   r   r   r   r   <module>   s2   



