
    U-fA'                        d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
mZmZmZmZmZmZmZ ddlmZmZ ddlmZ ded	efd
Z G d d          Z G d d          Z G d de          Z G d de          Z edd          Z G d dee          Z G d dee          Z G d d          Z  ee e ej!        e"                             ej!        e"<   dS )zJOSE utilities.    N)HashableMapping)
ModuleType)AnyCallableIteratorListTupleTypeVarUnioncast)ecrsa)cryptofuncreturnc                 D    t          t          j        |                     S N)classmethodabcabstractmethod)r   s    Z/home/cdr/domains/dharristours.com/map/certbot/lib/python3.11/site-packages/josepy/util.pyabstractclassmethodr      s    s)$//000    c                       e Zd ZdZdeej        ej        f         ddfdZde	de
fdZej        fdedefd	Zd
e
defdZdefdZde	fdZdS )ComparableX509zWrapper for OpenSSL.crypto.X509** objects that supports __eq__.

    :ivar wrapped: Wrapped certificate or certificate request.
    :type wrapped: `OpenSSL.crypto.X509` or `OpenSSL.crypto.X509Req`.

    wrappedr   Nc                     t          |t          j                  st          |t          j                  sJ || _        d S r   )
isinstancer   X509X509Reqr   selfr   s     r   __init__zComparableX509.__init__   s6    '6;//V:gv~3V3VVVVr   namec                 ,    t          | j        |          S r   )getattrr   r#   r%   s     r   __getattr__zComparableX509.__getattr__   s    t|T***r   filetypec                     t          | j        t          j                  rt          j        || j                  S t          j        || j                  S )aN  Dumps the object into a buffer with the specified encoding.

        :param int filetype: The desired encoding. Should be one of
            `OpenSSL.crypto.FILETYPE_ASN1`,
            `OpenSSL.crypto.FILETYPE_PEM`, or
            `OpenSSL.crypto.FILETYPE_TEXT`.

        :returns: Encoded X509 object.
        :rtype: bytes

        )r   r   r   r    dump_certificatedump_certificate_request)r#   r*   s     r   _dumpzComparableX509._dump!   sG     dlFK00 	C*8T\BBB .xFFFr   otherc                     t          || j                  st          S |                                 |                                k    S r   )r   	__class__NotImplementedr.   r#   r/   s     r   __eq__zComparableX509.__eq__3   s7    %00 	"!!zz||u{{}},,r   c                 R    t          | j        |                                 f          S r   )hashr1   r.   r#   s    r   __hash__zComparableX509.__hash__8   s    T^TZZ\\2333r   c                 L    d                     | j        j        | j                  S Nz<{0}({1!r})>)formatr1   __name__r   r7   s    r   __repr__zComparableX509.__repr__;   s    $$T^%<dlKKKr   )r<   
__module____qualname____doc__r   r   r    r!   r$   strr   r)   FILETYPE_ASN1intbytesr.   boolr4   r8   r=    r   r   r   r      s        fk6>&A B t    + + + + + + %+$8 G Gc GU G G G G$-C -D - - - -
4# 4 4 4 4L# L L L L L Lr   r   c                       e Zd ZU dZeZeg ef         ed<   de	e
j        e
j        ej        ej        f         fdZdedefdZdedefd	Zdefd
ZddZdS )ComparableKeyznComparable wrapper for ``cryptography`` keys.

    See https://github.com/pyca/cryptography/issues/2122.

    r8   r   c                     || _         d S r   )_wrappedr"   s     r   r$   zComparableKey.__init__H   s      r   r%   r   c                 ,    t          | j        |          S r   )r'   rJ   r(   s     r   r)   zComparableKey.__getattr__S   s    t}d+++r   r/   c                 t   t          || j                  r| j        j        |j        j        urt          S t	          | j        d          r*|                                 |                                k    S t	          | j        d          r*|                                 |                                k    S t          S )Nprivate_numberspublic_numbers)r   r1   rJ   r2   hasattrrM   rN   r3   s     r   r4   zComparableKey.__eq__V   s    5$.11
	"}&en.FFF!!T]$566 	"''))U-B-B-D-DDDT]$455 	"&&((E,@,@,B,BBB!!r   c                 L    d                     | j        j        | j                  S r:   )r;   r1   r<   rJ   r7   s    r   r=   zComparableKey.__repr__c   s    $$T^%<dmLLLr   c                     t          | j        t          j        t          j        f          r| S |                     | j                                                  S )zGet wrapped public key.)r   rJ   r   RSAPublicKeyWithSerializationr   'EllipticCurvePublicKeyWithSerializationr1   
public_keyr7   s    r   rT   zComparableKey.public_keyf   sN    M.0Z[
 
 	 K~~dm6688999r   N)r   rH   )r<   r>   r?   r@   r2   r8   r   rC   __annotations__r   r   RSAPrivateKeyWithSerializationrR   r   (EllipticCurvePrivateKeyWithSerializationrS   r$   rA   r   r)   rE   r4   r=   rT   rF   r   r   rH   rH   ?   s           #1Hhr3w000	 .-768
	  	  	  	 , , , , , ,"C "D " " " "M# M M M M: : : : : :r   rH   c                       e Zd ZdZdefdZdS )ComparableRSAKeyzWrapper for ``cryptography`` RSA keys.

    Wraps around:

    - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`
    - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`

    r   c           
         t          | j        t          j                  rZ|                                 }|j        }t          | j        |j        |j	        |j
        |j        |j        |j        |j        f          S t          | j        t          j                  r5|                                 }t          | j        |j        |j        f          S t!                      r   )r   rJ   r   rV   rM   rN   r6   r1   pqdmp1dmq1iqmpnerR   NotImplementedErrorr#   privpubs      r   r8   zComparableRSAKey.__hash__{   s     dmS%GHH 	8''))D%CDItyRURWY\Y^_   s'HII 	8%%''C6777!###r   Nr<   r>   r?   r@   rC   r8   rF   r   r   rY   rY   q   s9         $# $ $ $ $ $ $r   rY   c                       e Zd ZdZdefdZdS )ComparableECKeyzWrapper for ``cryptography`` EC keys.
    Wraps around:
    - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
    - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
    r   c                    t          | j        t          j                  rM|                                 }|j        }t          | j        |j        j	        |j
        |j        |j        f          S t          | j        t          j                  r@|                                 }t          | j        |j        j	        |j
        |j        f          S t                      r   )r   rJ   r   rW   rM   rN   r6   r1   curver%   xyprivate_valuerS   rb   rc   s      r   r8   zComparableECKey.__hash__   s     dmR%PQQ 	H''))D%CtGYZ[[[r'QRR 	H%%''CFGGG!###r   Nrf   rF   r   r   rh   rh      s9         $# $ $ $ $ $ $r   rh   GenericImmutableMapImmutableMap)boundc                       e Zd ZU dZdZeedf         ed<   	 deddfdZ	d	e
dede
fd
ZdedefdZdee         fdZdefdZdefdZdededdfdZdefdZdS )ro   z5Immutable key to value mapping with attribute access.rF   .	__slots__kwargsr   Nc                 f   t          |          t          | j                  k    rRt          d                    d                    | j                  |rd                    |          nd                    | j        D ]1}t
                              | ||                    |                     2d S )NzA__init__() takes exactly the following arguments: {0} ({1} given), none)setrr   	TypeErrorr;   joinobject__setattr__pop)r#   rs   slots      r   r$   zImmutableMap.__init__   s    v;;#dn----$fIIdn--F/Vtyy/@/@/@PV    N 	= 	=DtT6::d+;+;<<<<	= 	=r   r#   c                 8    i | |} t          |           di |S )zReturn updated map.rF   )type)r#   rs   itemss      r   updatezImmutableMap.update   s-    #5d#5f#5tDzz""E"""r   keyc                 ^    	 t          | |          S # t          $ r t          |          w xY wr   )r'   AttributeErrorKeyErrorr#   r   s     r   __getitem__zImmutableMap.__getitem__   s>    	 4%%% 	  	  	 3--	 s    ,c                 *    t          | j                  S r   )iterrr   r7   s    r   __iter__zImmutableMap.__iter__   s    DN###r   c                 *    t          | j                  S r   )lenrr   r7   s    r   __len__zImmutableMap.__len__   s    4>"""r   c                 ^     t          t           fd j        D                                 S )Nc              3   8   K   | ]}t          |          V  d S r   )r'   ).0r}   r#   s     r   	<genexpr>z(ImmutableMap.__hash__.<locals>.<genexpr>   s-      II$'$--IIIIIIr   )r6   tuplerr   r7   s   `r   r8   zImmutableMap.__hash__   s0    EIIII$.IIIIIJJJr   r%   valuec                      t          d          Nzcan't set attributer   r#   r%   r   s      r   r{   zImmutableMap.__setattr__       2333r   c                     d                     | j        j        d                    d |                                 D                                 S )Nz{0}({1})ru   c              3   H   K   | ]\  }}d                      ||          V  dS z	{0}={1!r}Nr;   r   r   r   s      r   r   z(ImmutableMap.__repr__.<locals>.<genexpr>   s6      TTek((e44TTTTTTr   )r;   r1   r<   ry   r   r7   s    r   r=   zImmutableMap.__repr__   sH      N#IITTtzz||TTTTT
 
 	
r   )r<   r>   r?   r@   rr   r
   rA   rU   r   r$   rn   r   r   r   r   rC   r   r8   r{   r=   rF   r   r   ro   ro      sD        ??!#IuS#X###+	= 	= 	= 	= 	= 	=#( #C #<O # # # #
 s  s        $(3- $ $ $ $# # # # #K# K K K K4 4C 4D 4 4 4 4
# 
 
 
 
 
 
r   c                       e Zd ZdZdZdededdfdZdedefd	Zde	e         fd
Z
defdZdeeeef         df         fdZdefdZdedefdZdededdfdZdefdZdS )
frozendictzFrozen dictionary.)_items_keysargsrs   r   Nc           
         |r|st          |          }nEt          |          dk    r$t          |d         t                    r	|d         }nt	                      t
                              | d|           t
                              | dt          t          |	                                                               d S )N   r   r   r   )
dictr   r   r   rx   rz   r{   r   sortedkeys)r#   r   rs   r   s       r   r$   zfrozendict.__init__   s     	$ 	LLEEYY!^^
47G < <^GEE++ 	451114%uzz||0D0D*E*EFFFFFr   r   c                     | j         |         S r   )r   r   s     r   r   zfrozendict.__getitem__   s    {3r   c                 *    t          | j                  S r   )r   r   r7   s    r   r   zfrozendict.__iter__   s    DJr   c                 *    t          | j                  S r   )r   r   r7   s    r   r   zfrozendict.__len__   s    4;r   .c                 D     t           fd j        D                       S )Nc              3   ,   K   | ]}||         fV  d S r   rF   )r   r   r#   s     r   r   z+frozendict._sorted_items.<locals>.<genexpr>   s,      <<#c49%<<<<<<r   )r   r   r7   s   `r   _sorted_itemszfrozendict._sorted_items   s(    <<<<<<<<<<r   c                 D    t          |                                           S r   )r6   r   r7   s    r   r8   zfrozendict.__hash__   s    D&&(()))r   r%   c                 X    	 | j         |         S # t          $ r t          |          w xY wr   )r   r   r   r(   s     r   r)   zfrozendict.__getattr__   s=    	';t$$ 	' 	' 	' &&&	's    )r   c                      t          d          r   r   r   s      r   r{   zfrozendict.__setattr__   r   r   c                     d                     d                    d |                                 D                                 S )Nzfrozendict({0})ru   c              3   H   K   | ]\  }}d                      ||          V  dS r   r   r   s      r   r   z&frozendict.__repr__.<locals>.<genexpr>   s6      \\ek((e44\\\\\\r   )r;   ry   r   r7   s    r   r=   zfrozendict.__repr__   sD     ''II\\tGYGYG[G[\\\\\
 
 	
r   )r<   r>   r?   r@   rr   r   r$   rA   r   r   r   rC   r   r
   r   r8   r)   r{   r=   rF   r   r   r   r      sY       #IGc GS GT G G G G s  s         (3-                 =uU38_c%9: = = = =*# * * * *' ' ' ' ' '4 4C 4D 4 4 4 4
# 
 
 
 
 
 
r   r   c                   n    e Zd ZdZdeddfdZdedefdZdededdfd	Z	deddfd
Z
dee         fdZdS )_UtilDeprecationModulez
    Internal class delegating to a module, and displaying warnings when attributes
    related to the deprecated "abstractclassmethod" attributes in the josepy.util module.
    moduler   Nc                     || j         d<   d S N_module)__dict__)r#   r   s     r   r$   z_UtilDeprecationModule.__init__  s    #)i   r   attrc                 p    |dk    rt          j        dt          d           t          | j        |          S )Nr   zThe abstractclassmethod attribute in josepy.util is deprecated and will be removed soon. Please use the built-in decorators @classmethod and @abc.abstractmethod together instead.   )
stacklevel)warningswarnDeprecationWarningr'   r   r#   r   s     r   r)   z"_UtilDeprecationModule.__getattr__  sH    (((M8 #    t|T***r   r   c                 2    t          | j        ||           d S r   )setattrr   )r#   r   r   s      r   r{   z"_UtilDeprecationModule.__setattr__  s    dE*****r   c                 0    t          | j        |           d S r   )delattrr   r   s     r   __delattr__z"_UtilDeprecationModule.__delattr__  s    d#####r   c                 2    dgt          | j                  z   S r   )dirr   r7   s    r   __dir__z_UtilDeprecationModule.__dir__  s    {S....r   )r<   r>   r?   r@   r   r$   rA   r   r)   r{   r   r	   r   rF   r   r   r   r     s         
*z *d * * * *	+ 	+ 	+ 	+ 	+ 	++ +C +D + + + +$ $ $ $ $ $/c / / / / / /r   r   )#r@   r   sysr   collections.abcr   r   typesr   typingr   r   r   r	   r
   r   r   r   )cryptography.hazmat.primitives.asymmetricr   r   OpenSSLr   r   r   r   rH   rY   rh   rn   ro   r   r   modulesr<   rF   r   r   <module>r      sS     



 



  - - - - - - - -       M M M M M M M M M M M M M M M M M M M M = = = = = = = =      1h 1; 1 1 1 1*L *L *L *L *L *L *L *LZ/: /: /: /: /: /: /: /:d$ $ $ $ $} $ $ $4$ $ $ $ $m $ $ $* g3>JJJ ,
 ,
 ,
 ,
 ,
7H ,
 ,
 ,
^-
 -
 -
 -
 -
( -
 -
 -
f/ / / / / / / /> Z)?)?H@U)V)VWWH   r   