
     h^"                     :   d dl Z d dlmZ d dlmZ d dlmZmZ ddlm	Z	 ddl
mZ  ed	           G d
 d                      Z G d de j                  Z G d d          Zdej        defdZ G d de          Z G d de          Z G d de          ZdS )    N)	dataclass)Optional)keysx509   )process_general_subtrees)PKIXValidationParamsT)frozenc                   f    e Zd ZU dZdZed         ed<   	 dZee         ed<   	 dZ	ee         ed<   dS )TrustQualifierszY
    .. versionadded 0.20.0

    Parameters that allow a trust root to be qualified.
    Nr	   standard_parametersmax_path_lengthmax_aa_path_length)
__name__
__module____qualname____doc__r   r   __annotations__r   intr        [/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko_certvalidator/authority.pyr   r      sq           =A"89@@@
 &*OXc])))
 )-,,, r   r   c                       e Zd ZdZedej        fd            Zedej	        fd            Z
ed             Zd Zd Zedee         fd            Zd	ej        defd
ZdS )	AuthorityzM
    .. versionadded:: 0.20.0

    Abstract authority, i.e. a named key.
    returnc                     t           )z'
        The authority's name.
        NotImplementedErrorselfs    r   namezAuthority.name/   
    
 "!r   c                     t           )z-
        The authority's public key.
        r   r   s    r   
public_keyzAuthority.public_key6   r"   r   c                     t           )zm
        A hashable unique identifier of the authority, used in ``__eq__``
        and ``__hash__``.
        r   r   s    r   hashablezAuthority.hashable=   s
     "!r   c                 *    t          | j                  S N)hashr&   r   s    r   __hash__zAuthority.__hash__E   s    DM"""r   c                 P    t          |t                    sdS | j        |j        k    S NF)
isinstancer   r&   r    others     r   __eq__zAuthority.__eq__H   s(    %++ 	5}..r   c                     t           )z
        Key ID as (potentially) referenced in an authorityKeyIdentifier
        extension. Only used to eliminate non-matching trust anchors,
        never to retrieve keys or to definitively identify trust anchors.
        r   r   s    r   key_idzAuthority.key_idN   s
     "!r   certc                 j    |j         | j        k    rdS |j        r| j        r|j        | j        k    rdS dS )z
        Function to determine whether this trust root could potentially be an
        issuer of a given certificate.
        This function is used during path building.

        :param cert:
            The certificate to evaluate.
        FT)issuerr!   authority_key_identifierr2   r    r3   s     r   is_potential_issuer_ofz Authority.is_potential_issuer_ofW   sF     ;$)##5( 	T[ 	,;;utr   N)r   r   r   r   propertyr   Namer!   r   PublicKeyInfor$   r&   r*   r0   r   bytesr2   Certificateboolr8   r   r   r   r   r   (   s          "di " " " X" "D. " " " X" " " X"# # #/ / / " " " " X"4+;       r   r   c                   v    e Zd ZdZ	 ddedee         fdZedefd            Z	edefd            Z
d	 Zd
 ZdS )TrustAnchorz
    Abstract trust root. A trust root is an authority with trust qualifiers.
    Equality of trust roots reduces to equality of authorities.
    N	authorityqualsc                 "    || _         || _        d S r(   )
_authority_quals)r    rA   rB   s      r   __init__zTrustAnchor.__init__n   s     $r   r   c                     | j         S r(   )rD   r   s    r   rA   zTrustAnchor.authorityt   s
    r   c                 ,    | j         pt                      S )z0
        Qualifiers for the trust root.
        )rE   r   r   s    r   trust_qualifierszTrustAnchor.trust_qualifiersx   s    
 {/o///r   c                 L    t          |t                    o|j        | j        k    S r(   )r-   r@   rD   r.   s     r   r0   zTrustAnchor.__eq__   s&    uk** 4 DO3	
r   c                 *    t          | j                  S r(   )r)   rD   r   s    r   r*   zTrustAnchor.__hash__   s    DO$$$r   r(   )r   r   r   r   r   r   r   rF   r9   rA   rI   r0   r*   r   r   r   r@   r@   h   s          HL "+3O+D    9    X 0/ 0 0 0 X0
 
 
% % % % %r   r@   r3   r   c                    d}dx}}| j         kd}| j         }|d         }t          |t          j                  rt	          |          }|d         }t          |t          j                  rt	          |          }d}| j        "d}| j        }t          d |D                       }d}	|r%t          |pt          dg          |du||          }	t          | j	        |		          S )
a  
    Extract trust qualifiers from data and extensions of a certificate.

    .. note::
        Recall that any property of a trust root other than its name and public
        key are in principle irrelevant to the PKIX validation algorithm
        itself.
        This function is merely a helper function that allows the certificate's
        other data to be conveniently gathered to populate the default
        validation parameters for paths deriving from that trust root.

    :param cert:
        The certificate from which to extract qualifiers (usually a
        self-signed one)
    :return:
        A :class:`TrustQualifiers` object with the extracted qualifiers.
    FNTpermitted_subtreesexcluded_subtreesc                 (    g | ]}|d          j         S )policy_identifier)dotted).0pol_infos     r   
<listcomp>z*derive_quals_from_cert.<locals>.<listcomp>   s!    OOOhX)*1OOOr   
any_policy)user_initial_policy_setinitial_explicit_policyinitial_permitted_subtreesinitial_excluded_subtrees)r   r   )
name_constraints_valuer-   r   GeneralSubtreesr   certificate_policies_value	frozensetr	   r   r   )
r3   	ext_foundrM   rN   nc_extpermitted_valexcluded_valacceptable_policiespolicies_valparamss
             r   derive_quals_from_certre      s,   & I-11*".	'+'B34mT%9:: 	I!9-!H!H12lD$899 	G 8 F F&2	151P'OO,OOO
 
 F 

%#@y,'@'@ %8t$C'9&7	
 	
 	
 ,&   r   c                        e Zd ZdZdej        fdZedej        fd            Z	ed             Z
ed             Zedee         fd            Zedej        fd	            Zdej        f fd
Z xZS )AuthorityWithCertzz
    .. versionadded:: 0.20.0

    Authority provisioned as a certificate.

    :param cert:
        The certificate.
    r3   c                     || _         d S r(   _certr7   s     r   rF   zAuthorityWithCert.__init__   s    


r   r   c                     | j         j        S r(   )rj   subjectr   s    r   r!   zAuthorityWithCert.name   s    z!!r   c                     | j         j        S r(   )rj   r$   r   s    r   r$   zAuthorityWithCert.public_key   s    z$$r   c                 Z    | j         }|j        j        |j                                        fS r(   )rj   rl   r&   r$   dumpr7   s     r   r&   zAuthorityWithCert.hashable   s'    z|$do&:&:&<&<<<r   c                     | j         j        S r(   )rj   key_identifierr   s    r   r2   zAuthorityWithCert.key_id   s    z((r   c                     | j         S r(   ri   r   s    r   certificatezAuthorityWithCert.certificate   
    zr   c                     t                                          |          sdS |j        r|j        | j        j        k    rdS dS )NFT)superr8   authority_issuer_serialrj   issuer_serial)r    r3   	__class__s     r   r8   z(AuthorityWithCert.is_potential_issuer_of   sJ    ww--d33 	5' 	+tz/GGGutr   )r   r   r   r   r   r=   rF   r9   r:   r!   r$   r&   r   r<   r2   rs   r8   __classcell__ry   s   @r   rg   rg      s#        T-     "di " " " X" % % X% = = X= ) ) ) ) X) T-    X4+;          r   rg   c                        e Zd ZdZ	 	 ddej        dee         def fdZ	e
dej        fd	            Ze
defd
            Z xZS )CertTrustAnchora  
    .. versionadded:: 0.20.0

    Trust anchor provisioned as a certificate.

    :param cert:
        The certificate, usually self-signed.
    :param quals:
        Explicit trust qualifiers.
    :param derive_default_quals_from_cert:
        Flag indicating to derive default trust qualifiers from the certificate
        content if explicit ones are not provided. Defaults to ``False``.
    NFr3   rB   derive_default_quals_from_certc                     t          |          }|| _        t                                          ||           || _        d S r(   )rg   rj   rv   rF   _derive)r    r3   rB   r~   rA   ry   s        r   rF   zCertTrustAnchor.__init__   s>     &d++	
E***5r   r   c                     | j         S r(   ri   r   s    r   rs   zCertTrustAnchor.certificate  rt   r   c                     | j         | j         S | j        rt          | j                  x| _         }|S t	                      S r(   )rE   r   re   rj   r   )r    rB   s     r   rI   z CertTrustAnchor.trust_qualifiers  sC    ;";\ 	%"8"D"DDDK%L"$$$r   r,   )r   r   r   r   r   r=   r   r   r>   rF   r9   rs   rI   rz   r{   s   @r   r}   r}      s         " ,0/4		6 	6	6 (	6 )-		6 	6 	6 	6 	6 	6 T-    X %/ % % % X% % % % %r   r}   c                       e Zd ZdZdej        dej        fdZe	dej        fd            Z
e	d             Ze	dee         fd            Ze	d	             Zd
S )NamedKeyAuthorityz
    Authority provisioned as a named key.

    :param entity_name:
        The name of the entity that controls the private key of the trust root.
    :param public_key:
        The trust root's public key.
    entity_namer$   c                 "    || _         || _        d S r(   )_name_public_key)r    r   r$   s      r   rF   zNamedKeyAuthority.__init__   s     
%r   r   c                     | j         S r(   )r   r   s    r   r!   zNamedKeyAuthority.name$  rt   r   c                     | j         S r(   )r   r   s    r   r$   zNamedKeyAuthority.public_key(  s    r   c                     d S r(   r   r   s    r   r2   zNamedKeyAuthority.key_id,  s    tr   c                 L    | j         j        | j                                        fS r(   )r   r&   r   ro   r   s    r   r&   zNamedKeyAuthority.hashable0  s!    z"D$4$9$9$;$;;;r   N)r   r   r   r   r   r:   r   r;   rF   r9   r!   r$   r   r<   r2   r&   r   r   r   r   r     s         &DI &4;M & & & & di    X     X      X < < X< < <r   r   )abcdataclassesr   typingr   
asn1cryptor   r   
name_treesr   policy_declr	   r   ABCr   r@   r=   re   rg   r}   r   r   r   r   <module>r      s   



 ! ! ! ! ! !       ! ! ! ! ! ! ! ! 0 0 0 0 0 0 - - - - - -
 $       4= = = = = = = =@% % % % % % % %B6!1 6o 6 6 6 6r( ( ( ( (	 ( ( (V&% &% &% &% &%k &% &% &%R< < < < <	 < < < < <r   