
     fِ              	         d dl mZ d dlZd dlZd dlZd dlZ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mZmZmZmZmZmZmZ d dlmZmZmZ d dlmZmZmZm Z  d d	l!m"Z"m#Z# d d
l$m%Z%  ej                  ddd      Z&ejN                  ejP                  ejR                  ejT                  ejV                  ejX                  ejZ                  ej\                  ej^                  f   Z0 G d de1      Z2	 	 	 	 	 	 d.dZ3	 	 	 	 	 	 d/dZ4d0dZ5 G d d      Z6 G d d      Z7 G d dejp                        Z9 G d de1      Z: G d dejv                        Z<e<j{                  ejx                          G d dejv                        Z>e>j{                  ej|                          G d d e>      Z? G d! d"ejv                        Z@e@j{                  ej                          G d# d$ejv                        ZAeAj{                  ej                         ej                  ZBej                  ZCej                  ZDej                  ZEej                  ZFej                  ZGej                  ZH G d% d&      ZI G d' d(      ZJ G d) d*      ZK G d+ d,      ZLd1d-ZMy)2    )annotationsN)utils)x509)hashesserialization)dsaeced448ed25519paddingrsax448x25519) CertificateIssuerPrivateKeyTypesCertificateIssuerPublicKeyTypesCertificatePublicKeyTypes)	Extension
ExtensionsExtensionType_make_sequence_methods)Name	_ASN1Type)ObjectIdentifieri     c                        e Zd Zd fdZ xZS )AttributeNotFoundc                2    t         |   |       || _        y N)super__init__oid)selfmsgr!   	__class__s      P/var/www/html/py/new-venv/lib/python3.12/site-packages/cryptography/x509/base.pyr    zAttributeNotFound.__init__9   s        )r#   strr!   r   returnNone__name__
__module____qualname__r    __classcell__r$   s   @r%   r   r   8   s     r&   r   c                Z    |D ]&  }|j                   | j                   k(  st        d       y )Nz$This extension has already been set.)r!   
ValueError)	extension
extensionses      r%   _reject_duplicate_extensionr5   >   s1    
  E55IMM!CDDEr&   c                :    |D ]  \  }}}|| k(  st        d       y )Nz$This attribute has already been set.)r1   )r!   
attributesattr_oid_s       r%   _reject_duplicate_attributer:   H   s.    
 % E!Qs?CDDEr&   c                    | j                   =| j                         }|r|nt        j                         }| j	                  d      |z
  S | S )zNormalizes a datetime to a naive datetime in UTC.

    time -- datetime to normalize. Assumed to be in UTC if not timezone
            aware.
    Ntzinfo)r=   	utcoffsetdatetime	timedeltareplace)timeoffsets     r%   _convert_to_naive_utc_timerD   R   sG     {{!!x'9'9';||4|(611r&   c                      e Zd Zej                  j
                  f	 	 	 	 	 	 	 ddZed	d       Zed
d       ZddZ	ddZ
ddZy)	Attributec                .    || _         || _        || _        y r   )_oid_value_type)r"   r!   valuerJ   s       r%   r    zAttribute.__init__a   s     	
r&   c                    | j                   S r   )rH   r"   s    r%   r!   zAttribute.oidk   s    yyr&   c                    | j                   S r   )rI   rM   s    r%   rK   zAttribute.valueo   s    {{r&   c                <    d| j                    d| j                  dS )Nz<Attribute(oid=z, value=)>)r!   rK   rM   s    r%   __repr__zAttribute.__repr__s   s     
(4::.CCr&   c                    t        |t              st        S | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S r   )
isinstancerF   NotImplementedr!   rK   rJ   r"   others     r%   __eq__zAttribute.__eq__v   sS    %+!! HH		! *

ekk)*

ekk)	
r&   c                Z    t        | j                  | j                  | j                  f      S r   )hashr!   rK   rJ   rM   s    r%   __hash__zAttribute.__hash__   s     TXXtzz4::677r&   N)r!   r   rK   bytesrJ   intr(   r)   r(   r   r(   r[   r(   r'   rV   objectr(   boolr(   r\   )r+   r,   r-   r   
UTF8StringrK   r    propertyr!   rQ   rW   rZ    r&   r%   rF   rF   `   sv    
 ))//	  	
 
    D
8r&   rF   c                  D    e Zd Z	 	 	 	 ddZ ed      \  ZZZddZddZ	y)	
Attributesc                $    t        |      | _        y r   )list_attributes)r"   r7   s     r%   r    zAttributes.__init__   s      
+r&   rk   c                "    d| j                    dS )Nz<Attributes(rP   )rk   rM   s    r%   rQ   zAttributes.__repr__   s    d../r22r&   c                V    | D ]  }|j                   |k(  s|c S  t        d| d|      )NzNo z attribute was found)r!   r   )r"   r!   attrs      r%   get_attribute_for_oidz Attributes.get_attribute_for_oid   s:     	Dxx3	  #cU*> ?EEr&   N)r7   ztyping.Iterable[Attribute]r(   r)   r_   )r!   r   r(   rF   )
r+   r,   r-   r    r   __len____iter____getitem__rQ   ro   rf   r&   r%   rh   rh      s7    ,., 
, &<M%J"GX{3Fr&   rh   c                      e Zd ZdZdZy)Versionr      N)r+   r,   r-   v1v3rf   r&   r%   rt   rt      s    	
B	
Br&   rt   c                        e Zd Zd fdZ xZS )InvalidVersionc                2    t         |   |       || _        y r   )r   r    parsed_version)r"   r#   r{   r$   s      r%   r    zInvalidVersion.__init__   s    ,r&   )r#   r'   r{   r\   r(   r)   r*   r/   s   @r%   ry   ry      s    - -r&   ry   c                     e Zd Zej                  dd       Zeej                  dd              Zeej                  dd              Zej                  dd       Z	eej                  dd              Z
eej                  dd              Zeej                  dd              Zeej                  dd              Zeej                  dd	              Zeej                  dd
              Zeej                  dd              Zeej                  	 	 dd              Zeej                  dd              Zeej                  	 	 d d              Zeej                  d!d              Zeej                  d"d              Zeej                  d"d              Zeej                  d"d              Zej                  d#d       Zej                  dd       Zej                  d$d       Zej                  d%d       Zy)&Certificatec                     yz4
        Returns bytes using digest passed.
        Nrf   r"   	algorithms     r%   fingerprintzCertificate.fingerprint       r&   c                     y)z3
        Returns certificate serial number
        Nrf   rM   s    r%   serial_numberzCertificate.serial_number   r   r&   c                     y)z1
        Returns the certificate version
        Nrf   rM   s    r%   versionzCertificate.version   r   r&   c                     yz(
        Returns the public key
        Nrf   rM   s    r%   
public_keyzCertificate.public_key   r   r&   c                     y)zA
        Returns the ObjectIdentifier of the public key.
        Nrf   rM   s    r%   public_key_algorithm_oidz$Certificate.public_key_algorithm_oid   r   r&   c                     y)z?
        Not before time (represented as UTC datetime)
        Nrf   rM   s    r%   not_valid_beforezCertificate.not_valid_before   r   r&   c                     y)zK
        Not before time (represented as a non-naive UTC datetime)
        Nrf   rM   s    r%   not_valid_before_utcz Certificate.not_valid_before_utc   r   r&   c                     y)z>
        Not after time (represented as UTC datetime)
        Nrf   rM   s    r%   not_valid_afterzCertificate.not_valid_after   r   r&   c                     y)zJ
        Not after time (represented as a non-naive UTC datetime)
        Nrf   rM   s    r%   not_valid_after_utczCertificate.not_valid_after_utc   r   r&   c                     y)z1
        Returns the issuer name object.
        Nrf   rM   s    r%   issuerzCertificate.issuer   r   r&   c                     yz2
        Returns the subject name object.
        Nrf   rM   s    r%   subjectzCertificate.subject   r   r&   c                     yzt
        Returns a HashAlgorithm corresponding to the type of the digest signed
        in the certificate.
        Nrf   rM   s    r%   signature_hash_algorithmz$Certificate.signature_hash_algorithm   r   r&   c                     yzJ
        Returns the ObjectIdentifier of the signature algorithm.
        Nrf   rM   s    r%   signature_algorithm_oidz#Certificate.signature_algorithm_oid   r   r&   c                     yz=
        Returns the signature algorithm parameters.
        Nrf   rM   s    r%   signature_algorithm_parametersz*Certificate.signature_algorithm_parameters   r   r&   c                     y)z/
        Returns an Extensions object.
        Nrf   rM   s    r%   r3   zCertificate.extensions	  r   r&   c                     yz.
        Returns the signature bytes.
        Nrf   rM   s    r%   	signaturezCertificate.signature  r   r&   c                     y)zR
        Returns the tbsCertificate payload bytes as defined in RFC 5280.
        Nrf   rM   s    r%   tbs_certificate_bytesz!Certificate.tbs_certificate_bytes  r   r&   c                     y)zh
        Returns the tbsCertificate payload bytes with the SCT list extension
        stripped.
        Nrf   rM   s    r%   tbs_precertificate_bytesz$Certificate.tbs_precertificate_bytes  r   r&   c                     yz"
        Checks equality.
        Nrf   rU   s     r%   rW   zCertificate.__eq__&  r   r&   c                     yz"
        Computes a hash.
        Nrf   rM   s    r%   rZ   zCertificate.__hash__,  r   r&   c                     y)zB
        Serializes the certificate to PEM or DER format.
        Nrf   r"   encodings     r%   public_byteszCertificate.public_bytes2  r   r&   c                     y)z
        This method verifies that certificate issuer name matches the
        issuer subject name and that the certificate is signed by the
        issuer's private key. No other validation is performed.
        Nrf   )r"   r   s     r%   verify_directly_issued_byz%Certificate.verify_directly_issued_by8  r   r&   Nr   zhashes.HashAlgorithmr(   r[   rc   )r(   rt   r(   r   r]   r(   datetime.datetimer(   r   r(   zhashes.HashAlgorithm | Noner(   z0None | padding.PSS | padding.PKCS1v15 | ec.ECDSAr(   r   r^   r`   r   zserialization.Encodingr(   r[   )r   r}   r(   r)   )r+   r,   r-   abcabstractmethodr   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r   r   rW   rZ   r   r   rf   r&   r%   r}   r}      s    
   
   
 	 
   
   
   
   
   
   
   
 	$     
 	9     
   
   
    	 
 	 
 	 
 	 r&   r}   )	metaclassc                      e Zd Zeej
                  dd              Zeej
                  dd              Zeej
                  dd              Zeej
                  dd              Z	y)	RevokedCertificatec                     y)zG
        Returns the serial number of the revoked certificate.
        Nrf   rM   s    r%   r   z RevokedCertificate.serial_numberF  r   r&   c                     y)zH
        Returns the date of when this certificate was revoked.
        Nrf   rM   s    r%   revocation_datez"RevokedCertificate.revocation_dateM  r   r&   c                     y)zl
        Returns the date of when this certificate was revoked as a non-naive
        UTC datetime.
        Nrf   rM   s    r%   revocation_date_utcz&RevokedCertificate.revocation_date_utcT  r   r&   c                     y)zW
        Returns an Extensions object containing a list of Revoked extensions.
        Nrf   rM   s    r%   r3   zRevokedCertificate.extensions\  r   r&   Nrc   r   r   )
r+   r,   r-   re   r   r   r   r   r   r3   rf   r&   r%   r   r   E  s      
   
      r&   r   c                  h    e Zd Z	 	 	 	 	 	 ddZedd       Zed	d       Zed	d       Zed
d       Zy)_RawRevokedCertificatec                .    || _         || _        || _        y r   _serial_number_revocation_date_extensionsr"   r   r   r3   s       r%   r    z_RawRevokedCertificate.__init__i       , /%r&   c                    | j                   S r   )r   rM   s    r%   r   z$_RawRevokedCertificate.serial_numbers  s    """r&   c                f    t        j                  dt        j                  d       | j                  S )Nuk   Properties that return a naïve datetime object have been deprecated. Please switch to revocation_date_utc.ru   )
stacklevel)warningswarnr   DeprecatedIn42r   rM   s    r%   r   z&_RawRevokedCertificate.revocation_datew  s.    @  		
 $$$r&   c                j    | j                   j                  t        j                  j                        S )Nr<   )r   rA   r?   timezoneutcrM   s    r%   r   z*_RawRevokedCertificate.revocation_date_utc  s(    $$,,H4E4E4I4I,JJr&   c                    | j                   S r   )r   rM   s    r%   r3   z!_RawRevokedCertificate.extensions  s    r&   N)r   r\   r   r   r3   r   rc   r   r   )	r+   r,   r-   r    re   r   r   r   r3   rf   r&   r%   r   r   h  su    && +& 	& # # % % K K    r&   r   c                     e Zd Zej                  dd       Zej                  dd       Zej                  	 	 	 	 dd       Zeej                  	 	 dd              Z	eej                  dd              Z
eej                  	 	 dd              Zeej                  dd              Zeej                  dd              Zeej                  dd	              Zeej                  dd
              Zeej                  dd              Zeej                  d d              Zeej                  d!d              Zeej                  d!d              Zej                  d"d       Zej                  d#d       Zej.                  d$d       Zej.                  d%d       Zej                  	 	 	 	 d&d       Zej                  d'd       Zej                  	 	 	 	 d(d       Zy))CertificateRevocationListc                     y)z:
        Serializes the CRL to PEM or DER format.
        Nrf   r   s     r%   r   z&CertificateRevocationList.public_bytes  r   r&   c                     yr   rf   r   s     r%   r   z%CertificateRevocationList.fingerprint  r   r&   c                     y)zs
        Returns an instance of RevokedCertificate or None if the serial_number
        is not in the CRL.
        Nrf   )r"   r   s     r%   (get_revoked_certificate_by_serial_numberzBCertificateRevocationList.get_revoked_certificate_by_serial_number  r   r&   c                     yr   rf   rM   s    r%   r   z2CertificateRevocationList.signature_hash_algorithm  r   r&   c                     yr   rf   rM   s    r%   r   z1CertificateRevocationList.signature_algorithm_oid  r   r&   c                     yr   rf   rM   s    r%   r   z8CertificateRevocationList.signature_algorithm_parameters  r   r&   c                     y)zC
        Returns the X509Name with the issuer of this CRL.
        Nrf   rM   s    r%   r   z CertificateRevocationList.issuer  r   r&   c                     y)z?
        Returns the date of next update for this CRL.
        Nrf   rM   s    r%   next_updatez%CertificateRevocationList.next_update  r   r&   c                     y)zc
        Returns the date of next update for this CRL as a non-naive UTC
        datetime.
        Nrf   rM   s    r%   next_update_utcz)CertificateRevocationList.next_update_utc  r   r&   c                     y)z?
        Returns the date of last update for this CRL.
        Nrf   rM   s    r%   last_updatez%CertificateRevocationList.last_update  r   r&   c                     y)zc
        Returns the date of last update for this CRL as a non-naive UTC
        datetime.
        Nrf   rM   s    r%   last_update_utcz)CertificateRevocationList.last_update_utc  r   r&   c                     y)zS
        Returns an Extensions object containing a list of CRL extensions.
        Nrf   rM   s    r%   r3   z$CertificateRevocationList.extensions  r   r&   c                     yr   rf   rM   s    r%   r   z#CertificateRevocationList.signature  r   r&   c                     y)zO
        Returns the tbsCertList payload bytes as defined in RFC 5280.
        Nrf   rM   s    r%   tbs_certlist_bytesz,CertificateRevocationList.tbs_certlist_bytes  r   r&   c                     yr   rf   rU   s     r%   rW   z CertificateRevocationList.__eq__  r   r&   c                     y)z<
        Number of revoked certificates in the CRL.
        Nrf   rM   s    r%   rp   z!CertificateRevocationList.__len__  r   r&   c                     y r   rf   r"   idxs     r%   rr   z%CertificateRevocationList.__getitem__   s    ;>r&   c                     y r   rf   r   s     r%   rr   z%CertificateRevocationList.__getitem__  s    CFr&   c                     y)zS
        Returns a revoked certificate (or slice of revoked certificates).
        Nrf   r   s     r%   rr   z%CertificateRevocationList.__getitem__  r   r&   c                     y)z8
        Iterator over the revoked certificates
        Nrf   rM   s    r%   rq   z"CertificateRevocationList.__iter__  r   r&   c                     y)zQ
        Verifies signature of revocation list against given public key.
        Nrf   )r"   r   s     r%   is_signature_validz,CertificateRevocationList.is_signature_valid  r   r&   Nr   r   )r   r\   r(   zRevokedCertificate | Noner   r]   r   r   )r(   datetime.datetime | Noner   r   r^   r`   rc   )r   r\   r(   r   )r   slicer(   list[RevokedCertificate])r   zint | slicer(   z-RevokedCertificate | list[RevokedCertificate])r(   z#typing.Iterator[RevokedCertificate])r   r   r(   rb   )r+   r,   r-   r   r   r   r   r   re   r   r   r   r   r   r   r   r   r3   r   r   rW   rp   typingoverloadrr   rq   r   rf   r&   r%   r   r     s    
 	 
 	 	"  	$     
 	9     
   
      
      
   
   
 	 
 	 
 __> >__F F	6  	 
 	9	 r&   r   c                     e Zd Zej                  dd       Zej                  dd       Zej                  dd       Zeej                  dd              Z	eej                  	 	 dd              Z
eej                  dd              Zeej                  	 	 dd              Zeej                  dd              Zeej                  dd	              Zej                  dd
       Zeej                  dd              Zeej                  dd              Zeej                  dd              Zej                  dd       Zy)CertificateSigningRequestc                     yr   rf   rU   s     r%   rW   z CertificateSigningRequest.__eq__!  r   r&   c                     yr   rf   rM   s    r%   rZ   z"CertificateSigningRequest.__hash__'  r   r&   c                     yr   rf   rM   s    r%   r   z$CertificateSigningRequest.public_key-  r   r&   c                     yr   rf   rM   s    r%   r   z!CertificateSigningRequest.subject3  r   r&   c                     yr   rf   rM   s    r%   r   z2CertificateSigningRequest.signature_hash_algorithm:  r   r&   c                     yr   rf   rM   s    r%   r   z1CertificateSigningRequest.signature_algorithm_oidD  r   r&   c                     yr   rf   rM   s    r%   r   z8CertificateSigningRequest.signature_algorithm_parametersK  r   r&   c                     y)z@
        Returns the extensions in the signing request.
        Nrf   rM   s    r%   r3   z$CertificateSigningRequest.extensionsT  r   r&   c                     y)z/
        Returns an Attributes object.
        Nrf   rM   s    r%   r7   z$CertificateSigningRequest.attributes[  r   r&   c                     y)z;
        Encodes the request to PEM or DER format.
        Nrf   r   s     r%   r   z&CertificateSigningRequest.public_bytesb  r   r&   c                     yr   rf   rM   s    r%   r   z#CertificateSigningRequest.signatureh  r   r&   c                     y)zd
        Returns the PKCS#10 CertificationRequestInfo bytes as defined in RFC
        2986.
        Nrf   rM   s    r%   tbs_certrequest_bytesz/CertificateSigningRequest.tbs_certrequest_byteso  r   r&   c                     y)z8
        Verifies signature of signing request.
        Nrf   rM   s    r%   r   z,CertificateSigningRequest.is_signature_validw  r   r&   c                     y)z:
        Get the attribute value for a given OID.
        Nrf   )r"   r!   s     r%   ro   z/CertificateSigningRequest.get_attribute_for_oid~  r   r&   Nr`   rc   r   r   r   r]   r   r   )r(   rh   r   r^   )r(   rb   )r!   r   r(   r[   )r+   r,   r-   r   r   rW   rZ   r   re   r   r   r   r   r3   r7   r   r   r  r   ro   rf   r&   r%   r  r     s    
 	 
 	 
   
 	$     
 	9     
   
 	 
   
      
 	 r&   r  c                      e Zd Zdg g f	 	 	 	 	 d	dZd
dZ	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 ddZ	 ddd	 	 	 	 	 	 	 	 	 ddZy) CertificateSigningRequestBuilderNc                .    || _         || _        || _        y)zB
        Creates an empty X.509 certificate request (v1).
        N)_subject_namer   rk   )r"   subject_namer3   r7   s       r%   r    z)CertificateSigningRequestBuilder.__init__  s     *%%r&   c                    t        |t              st        d      | j                  t	        d      t        || j                  | j                        S )zF
        Sets the certificate requestor's distinguished name.
        Expecting x509.Name object.&The subject name may only be set once.)rS   r   	TypeErrorr  r1   r  r   rk   r"   names     r%   r  z-CertificateSigningRequestBuilder.subject_name  sR     $%9::)EFF/$""D$4$4
 	
r&   c                    t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  g | j                  || j                        S )zE
        Adds an X.509 extension to the certificate request.
        "extension must be an ExtensionType)
rS   r   r  r   r!   r5   r   r  r  rk   r"   extvalcriticalr2   s       r%   add_extensionz.CertificateSigningRequestBuilder.add_extension  sn     &-0@AAfjj(F;	#It/?/?@/*d*	*
 	
r&   )_tagc               Z   t        |t              st        d      t        |t              st        d      |t        |t              st        d      t        || j                         ||j                  }nd}t        | j                  | j                  g | j                  |||f      S )zK
        Adds an X.509 attribute with an OID and associated value.
        zoid must be an ObjectIdentifierzvalue must be bytesNztag must be _ASN1Type)rS   r   r  r[   r   r:   rk   rK   r  r  r   )r"   r!   rK   r#  tags        r%   add_attributez.CertificateSigningRequestBuilder.add_attribute  s     #/0=>>%'122JtY$?344#C)9)9:**CC/2d2eS 12
 	
r&   rsa_paddingc                  | j                   t        d      |Zt        |t        j                  t        j
                  f      st        d      t        |t        j                        st        d      t        j                  | |||      S )zF
        Signs the request using the requestor's private key.
        z/A CertificateSigningRequest must have a subjectPadding must be PSS or PKCS1v15&Padding is only supported for RSA keys)r  r1   rS   r   PSSPKCS1v15r  r   RSAPrivateKey	rust_x509create_x509_csrr"   private_keyr   backendr(  s        r%   signz%CertificateSigningRequestBuilder.sign  s     %NOO"kGKK9I9I+JK ABBk3+<+<= HII((+y+
 	
r&   )r  Name | Noner3   list[Extension[ExtensionType]]r7   0list[tuple[ObjectIdentifier, bytes, int | None]])r  r   r(   r  )r   r   r!  rb   r(   r  )r!   r   rK   r[   r#  z_ASN1Type | Noner(   r  r   )
r2  r   r   _AllowedHashTypes | Noner3  
typing.Anyr(  %padding.PSS | padding.PKCS1v15 | Noner(   r  )r+   r,   r-   r    r  r"  r&  r4  rf   r&   r%   r  r    s     %)57GI	&!& 3& E	&


#
/3
	)
. "&

 

 
 
*
H #	
 >B
5
 ,
 	
 ;
 
#
r&   r  c                      e Zd ZU ded<   ddddddg f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 ddZddZdd	Z	dd
Z
	 	 	 	 	 	 ddZ	 ddd	 	 	 	 	 	 	 	 	 ddZy)CertificateBuilderr6  r   Nc                    t         j                  | _        || _        || _        || _        || _        || _        || _        || _	        y r   )
rt   rw   _version_issuer_namer  _public_keyr   _not_valid_before_not_valid_afterr   )r"   issuer_namer  r   r   r   r   r3   s           r%   r    zCertificateBuilder.__init__  sG      

')%+!1 /%r&   c           	         t        |t              st        d      | j                  t	        d      t        || j                  | j                  | j                  | j                  | j                  | j                        S )z3
        Sets the CA's distinguished name.
        r  %The issuer name may only be set once.)rS   r   r  r?  r1   r<  r  r@  r   rA  rB  r   r  s     r%   rC  zCertificateBuilder.issuer_name  sx     $%9::(DEE!""!!
 	
r&   c           	         t        |t              st        d      | j                  t	        d      t        | j                  || j                  | j                  | j                  | j                  | j                        S )z:
        Sets the requestor's distinguished name.
        r  r  )rS   r   r  r  r1   r<  r?  r@  r   rA  rB  r   r  s     r%   r  zCertificateBuilder.subject_name"  sx     $%9::)EFF!""!!
 	
r&   c           
        t        |t        j                  t        j                  t
        j                  t        j                  t        j                  t        j                  t        j                  f      st        d      | j                   t#        d      t%        | j&                  | j(                  || j*                  | j,                  | j.                  | j0                        S )zT
        Sets the requestor's public key (as found in the signing request).
        zExpecting one of DSAPublicKey, RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey, Ed448PublicKey, X25519PublicKey, or X448PublicKey.z$The public key may only be set once.)rS   r   DSAPublicKeyr   RSAPublicKeyr	   EllipticCurvePublicKeyr   Ed25519PublicKeyr
   Ed448PublicKeyr   X25519PublicKeyr   X448PublicKeyr  r@  r1   r<  r?  r  r   rA  rB  r   )r"   keys     r%   r   zCertificateBuilder.public_key4  s         ))(($$&&""
 !  'CDD!""!!
 	
r&   c           	     \   t        |t              st        d      | j                  t	        d      |dk  rt	        d      |j                         dk\  rt	        d      t        | j                  | j                  | j                  || j                  | j                  | j                        S )z5
        Sets the certificate serial number.
        'Serial number must be of integral type.'The serial number may only be set once.r   z%The serial number should be positive.   3The serial number should not be more than 159 bits.)rS   r\   r  r   r1   
bit_lengthr<  r?  r  r@  rA  rB  r   r"   numbers     r%   r   z CertificateBuilder.serial_numberY  s     &#&EFF*FGGQ;DEE #%E  """!!
 	
r&   c           	        t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  kD  rt	        d      t        | j                  | j                  | j                  | j                  || j                  | j                        S )z7
        Sets the certificate activation time.
        Expecting datetime object.z*The not valid before may only be set once.z>The not valid before date must be on or after 1950 January 1).zBThe not valid before date must be before the not valid after date.)rS   r?   r  rA  r1   rD   _EARLIEST_UTC_TIMErB  r<  r?  r  r@  r   r   r"   rB   s     r%   r   z#CertificateBuilder.not_valid_beforet  s     $ 1 12899!!-IJJ)$/$$$    ,8M8M1M  "!!
 	
r&   c           	        t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  k  rt	        d      t        | j                  | j                  | j                  | j                  | j                  || j                        S )z7
        Sets the certificate expiration time.
        rY  z)The not valid after may only be set once.z<The not valid after date must be on or after 1950 January 1.zAThe not valid after date must be after the not valid before date.)rS   r?   r  rB  r1   rD   rZ  rA  r<  r?  r  r@  r   r   r[  s     r%   r   z"CertificateBuilder.not_valid_after  s     $ 1 12899  ,HII)$/$$# 
 "".t---  """
 	
r&   c           
     H   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  | j                  | j                  | j                  g | j                  |      S )z=
        Adds an X.509 extension to the certificate.
        r  )rS   r   r  r   r!   r5   r   r<  r?  r  r@  r   rA  rB  r  s       r%   r"  z CertificateBuilder.add_extension  s     &-0@AAfjj(F;	#It/?/?@!""!!*d*	*
 	
r&   r'  c                  | j                   t        d      | j                  t        d      | j                  t        d      | j                  t        d      | j
                  t        d      | j                  t        d      |Zt        |t        j                  t        j                  f      st        d      t        |t        j                        st        d      t        j                  | |||      S )	zC
        Signs the certificate using the CA's private key.
        z&A certificate must have a subject namez&A certificate must have an issuer namez'A certificate must have a serial numberz/A certificate must have a not valid before timez.A certificate must have a not valid after timez$A certificate must have a public keyr*  r+  )r  r1   r?  r   rA  rB  r@  rS   r   r,  r-  r  r   r.  r/  create_x509_certificater1  s        r%   r4  zCertificateBuilder.sign  s     %EFF$EFF&FGG!!)NOO  (MNN#CDD"kGKK9I9I+JK ABBk3+<+<= HII00+y+
 	
r&   )rC  r5  r  r5  r   z CertificatePublicKeyTypes | Noner   
int | Noner   r   r   r   r3   r6  r(   r)   )r  r   r(   r<  )rO  r   r(   r<  )rW  r\   r(   r<  )rB   r   r(   r<  )r   r   r!  rb   r(   r<  r   )
r2  r   r   r8  r3  r9  r(  r:  r(   r}   )r+   r,   r-   __annotations__r    rC  r  r   r   r   r   r"  r4  rf   r&   r%   r<  r<    s   // $($(7;$(594857& & "& 5	&
 "& 3& 2& 3& 
&&
$
$#
&#
 
#
J
6
:
@
#
/3
	
4 #	%
 >B%
5%
 ,%
 	%
 ;%
 
%
r&   r<  c                      e Zd ZU ded<   ded<   dddg g f	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 dd	Z	 	 	 	 	 	 dd
Z	 	 	 	 ddZ		 ddd	 	 	 	 	 	 	 	 	 ddZ
y) CertificateRevocationListBuilderr6  r   r   _revoked_certificatesNc                J    || _         || _        || _        || _        || _        y r   )r?  _last_update_next_updater   rd  )r"   rC  r   r   r3   revoked_certificatess         r%   r    z)CertificateRevocationListBuilder.__init__  s,     (''%%9"r&   c                    t        |t              st        d      | j                  t	        d      t        || j                  | j                  | j                  | j                        S )Nr  rE  )
rS   r   r  r?  r1   rc  rf  rg  r   rd  )r"   rC  s     r%   rC  z,CertificateRevocationListBuilder.issuer_name  sf     +t,9::(DEE/&&
 	
r&   c                r   t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  kD  rt	        d      t        | j                  || j                  | j                  | j                        S )NrY  !Last update may only be set once.8The last update date must be on or after 1950 January 1.z9The last update date must be before the next update date.)rS   r?   r  rf  r1   rD   rZ  rg  rc  r?  r   rd  )r"   r   s     r%   r   z,CertificateRevocationListBuilder.last_update  s     +x'8'89899(@AA0=++J  ([4;L;L-LK  0&&
 	
r&   c                r   t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  k  rt	        d      t        | j                  | j                  || j                  | j                        S )NrY  rk  rl  z8The next update date must be after the last update date.)rS   r?   r  rg  r1   rD   rZ  rf  rc  r?  r   rd  )r"   r   s     r%   r   z,CertificateRevocationListBuilder.next_update(  s     +x'8'89899(@AA0=++J  ([4;L;L-LJ  0&&
 	
r&   c                   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  g | j                  || j                        S )zM
        Adds an X.509 extension to the certificate revocation list.
        r  )rS   r   r  r   r!   r5   r   rc  r?  rf  rg  rd  r  s       r%   r"  z.CertificateRevocationListBuilder.add_extension@  s     &-0@AAfjj(F;	#It/?/?@/*d*	*&&
 	
r&   c                    t        |t              st        d      t        | j                  | j
                  | j                  | j                  g | j                  |      S )z8
        Adds a revoked certificate to the CRL.
        z)Must be an instance of RevokedCertificate)	rS   r   r  rc  r?  rf  rg  r   rd  )r"   revoked_certificates     r%   add_revoked_certificatez8CertificateRevocationListBuilder.add_revoked_certificateS  sa     -/ABGHH/>d((>*=>
 	
r&   r'  c               t   | j                   t        d      | j                  t        d      | j                  t        d      |Zt	        |t
        j                  t
        j                  f      st        d      t	        |t        j                        st        d      t        j                  | |||      S )NzA CRL must have an issuer namez"A CRL must have a last update timez"A CRL must have a next update timer*  r+  )r?  r1   rf  rg  rS   r   r,  r-  r  r   r.  r/  create_x509_crlr1  s        r%   r4  z%CertificateRevocationListBuilder.signd  s     $=>>$ABB$ABB"kGKK9I9I+JK ABBk3+<+<= HII((+y+
 	
r&   )
rC  r5  r   r   r   r   r3   r6  rh  r   )rC  r   r(   rc  )r   r   r(   rc  )r   r   r(   rc  )r   r   r!  rb   r(   rc  )rp  r   r(   rc  r   )
r2  r   r   r8  r3  r9  r(  r:  r(   r   )r+   r,   r-   ra  r    rC  r   r   r"  rq  r4  rf   r&   r%   rc  rc    s
   //33 $(0404579;: : .: .	:
 3: 7:

	)

,
	)
0
,
	)
0
#
/3
	)
&
#5
	)
* #	
 >B
5
 ,
 	
 ;
 
#
r&   rc  c                  \    e Zd Zddg f	 	 	 	 	 ddZddZ	 	 	 	 d	dZ	 	 	 	 	 	 d
dZdddZy)RevokedCertificateBuilderNc                .    || _         || _        || _        y r   r   r   s       r%   r    z"RevokedCertificateBuilder.__init__  r   r&   c                   t        |t              st        d      | j                  t	        d      |dk  rt	        d      |j                         dk\  rt	        d      t        || j                  | j                        S )NrQ  rR  r   z$The serial number should be positiverS  rT  )	rS   r\   r  r   r1   rU  ru  r   r   rV  s     r%   r   z'RevokedCertificateBuilder.serial_number  s    &#&EFF*FGGQ;CDD #%E  )D))4+;+;
 	
r&   c                    t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      t        | j                  || j                        S )NrY  z)The revocation date may only be set once.z7The revocation date must be on or after 1950 January 1.)
rS   r?   r  r   r1   rD   rZ  ru  r   r   r[  s     r%   r   z)RevokedCertificateBuilder.revocation_date  s}     $ 1 12899  ,HII)$/$$I  )t'7'7
 	
r&   c                    t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  g | j                  |      S )Nr  )
rS   r   r  r   r!   r5   r   ru  r   r   r  s       r%   r"  z'RevokedCertificateBuilder.add_extension  sn     &-0@AAfjj(F;	#It/?/?@(!!*d*	*
 	
r&   c                    | j                   t        d      | j                  t        d      t        | j                   | j                  t	        | j
                              S )Nz/A revoked certificate must have a serial numberz1A revoked certificate must have a revocation date)r   r1   r   r   r   r   )r"   r3  s     r%   buildzRevokedCertificateBuilder.build  se    &NOO  (C  &!!t''(
 	
r&   )r   r`  r   r   r3   r6  )rW  r\   r(   ru  )rB   r   r(   ru  )r   r   r!  rb   r(   ru  r   )r3  r9  r(   r   )r+   r,   r-   r    r   r   r"  r{  rf   r&   r%   ru  ru    sj     %)4857	&!& 2& 3	&
$
%
	"
 
#
/3
	"

r&   ru  c                 Z    t         j                  t        j                  d      d      dz	  S )N   bigr   )r\   
from_bytesosurandomrf   r&   r%   random_serial_numberr    s     >>"**R.%0A55r&   )r2   zExtension[ExtensionType]r3   r6  r(   r)   )r!   r   r7   r7  r(   r)   )rB   r   r(   r   rc   )N
__future__r   r   r?   r  r   r   cryptographyr   "cryptography.hazmat.bindings._rustr   r/  cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   r	   r
   r   r   r   r   r   /cryptography.hazmat.primitives.asymmetric.typesr   r   r   cryptography.x509.extensionsr   r   r   r   cryptography.x509.namer   r   cryptography.x509.oidr   rZ  UnionSHA224SHA256SHA384SHA512SHA3_224SHA3_256SHA3_384SHA3_512_AllowedHashTypes	Exceptionr   r5   r:   rD   rF   rh   Enumrt   ry   ABCMetar}   registerr   r   r   r  load_pem_x509_certificateload_der_x509_certificateload_pem_x509_certificatesload_pem_x509_csrload_der_x509_csrload_pem_x509_crlload_der_x509_crlr  r<  rc  ru  r  rf   r&   r%   <module>r     s{  
 # 
  	    @ @	 	 	 
  3 2&X&&tQ2  LL
MM
MM
MM
MM
OO
OO
OO
OO	 	 E'E.E 
EE	E@E 
E!8 !8HF F(ejj 
-Y -[CKK [~   Y** +3;; @   I88 9 /  DP#++ Pf  " "9#F#F Gb#++ bL  " "9#F#F G &?? %?? &AA // // // // b
 b
Jr
 r
jN
 N
bF
 F
R6r&   