
     h              	          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 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j#        e
j$        e
j%        e
j&        e
j'        e
j(        e
j)        e
j*        e
j+        f         Z, G d de-          Z.dee         dej/        ee                  ddfdZ0de!dej/        ej1        e!e2ej3        e4         f                  ddfdZ5dej        dej        fdZ6 G d d          Z7 G d d          Z8 G d dej9                  Z: G d de-          Z; G d d e j<        !          Z=e=>                    ej=                    G d" d#e j<        !          Z?e?>                    ej?                    G d$ d%e?          Z@ G d& d'e j<        !          ZAeA>                    ejA                    G d( d)e j<        !          ZBeB>                    ejB                   	 d<d*e2d+ejC        de=fd,ZDd*e2dej/        e=         fd-ZE	 d<d*e2d+ejC        de=fd.ZF	 d<d*e2d+ejC        deBfd/ZG	 d<d*e2d+ejC        deBfd0ZH	 d<d*e2d+ejC        deAfd1ZI	 d<d*e2d+ejC        deAfd2ZJ G d3 d4          ZK G d5 d6          ZL G d7 d8          ZM G d9 d:          ZNde4fd;ZOdS )=    N)utils)x509)hashesserialization)dsaeced448ed25519rsax448x25519) CertificateIssuerPrivateKeyTypesCertificateIssuerPublicKeyTypesCertificatePublicKeyTypes)	Extension
ExtensionsExtensionType_make_sequence_methods)Name	_ASN1Type)ObjectIdentifieri     c                   ,     e Zd Zdededdf fdZ xZS )AttributeNotFoundmsgoidreturnNc                 X    t                                          |           || _        d S N)super__init__r   )selfr   r   	__class__s      R/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/cryptography/x509/base.pyr!   zAttributeNotFound.__init__6   s&        )__name__
__module____qualname__strr   r!   __classcell__r#   s   @r$   r   r   5   sS        C &6 4          r%   r   	extension
extensionsr   c                 N    |D ]!}|j         | j         k    rt          d          "d S )Nz$This extension has already been set.)r   
ValueError)r,   r-   es      r$   _reject_duplicate_extensionr1   ;   sD    
  E E5IM!!CDDD "E Er%   r   
attributesc                 B    |D ]\  }}}|| k    rt          d          d S )Nz$This attribute has already been set.)r/   )r   r2   attr_oid_s       r$   _reject_duplicate_attributer6   E   sD     % E E!Qs??CDDD E Er%   timec                     | j         D|                                 }|r|nt          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)r9   	utcoffsetdatetime	timedeltareplace)r7   offsets     r$   _convert_to_naive_utc_timer?   Q   sP     {!!!;x'9';';||4|((611r%   c            	           e Zd Zej        j        fdedededdfdZ	e
defd            Ze
defd            Zdefd	Zd
edefdZdefdZdS )	Attributer   value_typer   Nc                 0    || _         || _        || _        d S r   )_oid_valuerC   )r"   r   rB   rC   s       r$   r!   zAttribute.__init__`   s     	


r%   c                     | j         S r   )rE   r"   s    r$   r   zAttribute.oidj   s
    yr%   c                     | j         S r   )rF   rH   s    r$   rB   zAttribute.valuen   s
    {r%   c                 (    d| j          d| j        dS )Nz<Attribute(oid=z, value=)>)r   rB   rH   s    r$   __repr__zAttribute.__repr__r   s    CCC4:CCCCr%   otherc                     t          |t                    st          S | j        |j        k    o| j        |j        k    o| j        |j        k    S r   )
isinstancerA   NotImplementedr   rB   rC   r"   rM   s     r$   __eq__zAttribute.__eq__u   sO    %++ 	"!! H	! *
ek)*
ek)	
r%   c                 D    t          | j        | j        | j        f          S r   )hashr   rB   rC   rH   s    r$   __hash__zAttribute.__hash__   s    TXtz4:6777r%   )r&   r'   r(   r   
UTF8StringrB   r   bytesintr!   propertyr   r)   rL   objectboolrR   rU    r%   r$   rA   rA   _   s
       
 )/	   	
 
    %    X u    XD# D D D D
F 
t 
 
 
 
8# 8 8 8 8 8 8r%   rA   c                   n    e Zd Zdej        e         ddfdZ ed          \  ZZ	Z
defdZdedefdZdS )	
Attributesr2   r   Nc                 .    t          |          | _        d S r   )list_attributes)r"   r2   s     r$   r!   zAttributes.__init__   s      
++r%   ra   c                     d| j          dS )Nz<Attributes(rK   )ra   rH   s    r$   rL   zAttributes.__repr__   s    2d.2222r%   r   c                 R    | D ]}|j         |k    r|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   sH     	 	Dx3    ?c ? ? ?EEEr%   )r&   r'   r(   typingIterablerA   r!   r   __len____iter____getitem__r)   rL   r   re   r\   r%   r$   r^   r^      s        ,OI., 
, , , , &<%;M%J%J"GX{3# 3 3 3 3F)9 Fi F F F F F Fr%   r^   c                       e Zd ZdZdZdS )Versionr      N)r&   r'   r(   v1v3r\   r%   r$   rl   rl      s        	
B	
BBBr%   rl   c                   ,     e Zd Zdededdf fdZ xZS )InvalidVersionr   parsed_versionr   Nc                 X    t                                          |           || _        d S r   )r    r!   rr   )r"   r   rr   r#   s      r$   r!   zInvalidVersion.__init__   s)    ,r%   )r&   r'   r(   r)   rX   r!   r*   r+   s   @r$   rq   rq      sR        -C - - - - - - - - - - - -r%   rq   c                      e Zd Zej        dej        defd            Ze	ej        de
fd                        Ze	ej        defd                        Zej        defd            Ze	ej        dej        fd                        Ze	ej        dej        fd                        Ze	ej        defd	                        Ze	ej        defd
                        Ze	ej        dej        ej                 fd                        Ze	ej        defd                        Ze	ej        defd                        Ze	ej        defd                        Ze	ej        defd                        Ze	ej        defd                        Zej        de de!fd            Z"ej        de
fd            Z#ej        de$j%        defd            Z&ej        dd            Z'dS )Certificate	algorithmr   c                     dS z4
        Returns bytes using digest passed.
        Nr\   r"   rv   s     r$   fingerprintzCertificate.fingerprint         r%   c                     dS )z3
        Returns certificate serial number
        Nr\   rH   s    r$   serial_numberzCertificate.serial_number   r{   r%   c                     dS )z1
        Returns the certificate version
        Nr\   rH   s    r$   versionzCertificate.version   r{   r%   c                     dS z(
        Returns the public key
        Nr\   rH   s    r$   
public_keyzCertificate.public_key   r{   r%   c                     dS )z?
        Not before time (represented as UTC datetime)
        Nr\   rH   s    r$   not_valid_beforezCertificate.not_valid_before   r{   r%   c                     dS )z>
        Not after time (represented as UTC datetime)
        Nr\   rH   s    r$   not_valid_afterzCertificate.not_valid_after   r{   r%   c                     dS )z1
        Returns the issuer name object.
        Nr\   rH   s    r$   issuerzCertificate.issuer   r{   r%   c                     dS z2
        Returns the subject name object.
        Nr\   rH   s    r$   subjectzCertificate.subject   r{   r%   c                     dS zt
        Returns a HashAlgorithm corresponding to the type of the digest signed
        in the certificate.
        Nr\   rH   s    r$   signature_hash_algorithmz$Certificate.signature_hash_algorithm   r{   r%   c                     dS zJ
        Returns the ObjectIdentifier of the signature algorithm.
        Nr\   rH   s    r$   signature_algorithm_oidz#Certificate.signature_algorithm_oid   r{   r%   c                     dS )z/
        Returns an Extensions object.
        Nr\   rH   s    r$   r-   zCertificate.extensions   r{   r%   c                     dS z.
        Returns the signature bytes.
        Nr\   rH   s    r$   	signaturezCertificate.signature   r{   r%   c                     dS )zR
        Returns the tbsCertificate payload bytes as defined in RFC 5280.
        Nr\   rH   s    r$   tbs_certificate_bytesz!Certificate.tbs_certificate_bytes   r{   r%   c                     dS )zh
        Returns the tbsCertificate payload bytes with the SCT list extension
        stripped.
        Nr\   rH   s    r$   tbs_precertificate_bytesz$Certificate.tbs_precertificate_bytes   r{   r%   rM   c                     dS z"
        Checks equality.
        Nr\   rQ   s     r$   rR   zCertificate.__eq__  r{   r%   c                     dS z"
        Computes a hash.
        Nr\   rH   s    r$   rU   zCertificate.__hash__  r{   r%   encodingc                     dS )zB
        Serializes the certificate to PEM or DER format.
        Nr\   r"   r   s     r$   public_byteszCertificate.public_bytes  r{   r%   r   Nc                     dS )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.
        Nr\   )r"   r   s     r$   verify_directly_issued_byz%Certificate.verify_directly_issued_by  r{   r%   )r   ru   r   N)(r&   r'   r(   abcabstractmethodr   HashAlgorithmrW   rz   rY   rX   r}   rl   r   r   r   r;   r   r   r   r   r   rf   Optionalr   r   r   r   r-   r   r   r   rZ   r[   rR   rU   r   Encodingr   r   r\   r%   r$   ru   ru      s       V%9 e    
 s     X
      X
 	5    
 ("3     X
 !2     X
      X
      X
 	-	.    X )9     X
 J     X
 5     X
 u     X
 %     X 	F t    
 	#    
 	]%;     
 	     r%   ru   )	metaclassc                       e Zd Zeej        defd                        Zeej        dej        fd                        Z	eej        de
fd                        ZdS )RevokedCertificater   c                     dS )zG
        Returns the serial number of the revoked certificate.
        Nr\   rH   s    r$   r}   z RevokedCertificate.serial_number'  r{   r%   c                     dS )zH
        Returns the date of when this certificate was revoked.
        Nr\   rH   s    r$   revocation_datez"RevokedCertificate.revocation_date.  r{   r%   c                     dS )zW
        Returns an Extensions object containing a list of Revoked extensions.
        Nr\   rH   s    r$   r-   zRevokedCertificate.extensions5  r{   r%   N)r&   r'   r(   rY   r   r   rX   r}   r;   r   r   r-   r\   r%   r$   r   r   &  s        s     X
 !2     X
 J     X  r%   r   c                       e Zd Zdedej        defdZedefd            Zedej        fd            Z	edefd            Z
d	S )
_RawRevokedCertificater}   r   r-   c                 0    || _         || _        || _        d S r   _serial_number_revocation_date_extensionsr"   r}   r   r-   s       r$   r!   z_RawRevokedCertificate.__init__B  "     , /%r%   r   c                     | j         S r   )r   rH   s    r$   r}   z$_RawRevokedCertificate.serial_numberL  s    ""r%   c                     | j         S r   )r   rH   s    r$   r   z&_RawRevokedCertificate.revocation_dateP  s    $$r%   c                     | j         S r   )r   rH   s    r$   r-   z!_RawRevokedCertificate.extensionsT  s    r%   N)r&   r'   r(   rX   r;   r   r!   rY   r}   r   r-   r\   r%   r$   r   r   A  s        && "*& 	& & & & #s # # # X# %!2 % % % X%  J       X     r%   r   c                   D   e Zd Zej        dej        defd            Zej        de	j
        defd            Zej        dedej        e         fd            Zeej        dej        e	j
                 fd                        Zeej        defd	                        Zeej        defd
                        Zeej        dej        ej                 fd                        Zeej        dej        fd                        Zeej        defd                        Zeej        defd                        Zeej        defd                        Zej        dedefd            Z ej        defd            Z!ej"        dedefd            Z#ej"        de$dej%        e         fd            Z#ej        dej&        ee$f         dej&        eej%        e         f         fd            Z#ej        dej'        e         fd            Z(ej        de)defd            Z*dS )CertificateRevocationListr   r   c                     dS )z:
        Serializes the CRL to PEM or DER format.
        Nr\   r   s     r$   r   z&CertificateRevocationList.public_bytesZ  r{   r%   rv   c                     dS rx   r\   ry   s     r$   rz   z%CertificateRevocationList.fingerprint`  r{   r%   r}   c                     dS )zs
        Returns an instance of RevokedCertificate or None if the serial_number
        is not in the CRL.
        Nr\   )r"   r}   s     r$   (get_revoked_certificate_by_serial_numberzBCertificateRevocationList.get_revoked_certificate_by_serial_numberf  r{   r%   c                     dS r   r\   rH   s    r$   r   z2CertificateRevocationList.signature_hash_algorithmo  r{   r%   c                     dS r   r\   rH   s    r$   r   z1CertificateRevocationList.signature_algorithm_oidy  r{   r%   c                     dS )zC
        Returns the X509Name with the issuer of this CRL.
        Nr\   rH   s    r$   r   z CertificateRevocationList.issuer  r{   r%   c                     dS )z?
        Returns the date of next update for this CRL.
        Nr\   rH   s    r$   next_updatez%CertificateRevocationList.next_update  r{   r%   c                     dS )z?
        Returns the date of last update for this CRL.
        Nr\   rH   s    r$   last_updatez%CertificateRevocationList.last_update  r{   r%   c                     dS )zS
        Returns an Extensions object containing a list of CRL extensions.
        Nr\   rH   s    r$   r-   z$CertificateRevocationList.extensions  r{   r%   c                     dS r   r\   rH   s    r$   r   z#CertificateRevocationList.signature  r{   r%   c                     dS )zO
        Returns the tbsCertList payload bytes as defined in RFC 5280.
        Nr\   rH   s    r$   tbs_certlist_bytesz,CertificateRevocationList.tbs_certlist_bytes  r{   r%   rM   c                     dS r   r\   rQ   s     r$   rR   z CertificateRevocationList.__eq__  r{   r%   c                     dS )z<
        Number of revoked certificates in the CRL.
        Nr\   rH   s    r$   rh   z!CertificateRevocationList.__len__  r{   r%   idxc                     d S r   r\   r"   r   s     r$   rj   z%CertificateRevocationList.__getitem__      r%   c                     d S r   r\   r   s     r$   rj   z%CertificateRevocationList.__getitem__  r   r%   c                     dS )zS
        Returns a revoked certificate (or slice of revoked certificates).
        Nr\   r   s     r$   rj   z%CertificateRevocationList.__getitem__  r{   r%   c                     dS )z8
        Iterator over the revoked certificates
        Nr\   rH   s    r$   ri   z"CertificateRevocationList.__iter__  r{   r%   r   c                     dS )zQ
        Verifies signature of revocation list against given public key.
        Nr\   )r"   r   s     r$   is_signature_validz,CertificateRevocationList.is_signature_valid  r{   r%   N)+r&   r'   r(   r   r   r   r   rW   r   r   r   rz   rX   rf   r   r   r   rY   r   r   r   r   r   r;   r   r   r   r-   r   r   rZ   r[   rR   rh   overloadrj   sliceListUnionIteratorri   r   r   r\   r%   r$   r   r   Y  s       ]%;     
 	V%9 e    
 	 	+	,    	-	.    X )9     X
      X
 V_X->?     X
 X.     X
 J     X
 5     X
 E     X
 	F t    
 	    
 _s '9    _ _u 5G)H    _ 	<U
+	(&+6H*II	J    	&/*<=    
 	9	     r%   r   c                      e Zd Zej        dedefd            Zej        defd            Z	ej        de
fd            Zeej        defd                        Zeej        dej        ej                 fd                        Zeej        defd                        Zeej        defd	                        Zeej        defd
                        Zej        dej        defd            Zeej        defd                        Zeej        defd                        Zeej        defd                        Z ej        dedefd            Z!dS )CertificateSigningRequestrM   r   c                     dS r   r\   rQ   s     r$   rR   z CertificateSigningRequest.__eq__  r{   r%   c                     dS r   r\   rH   s    r$   rU   z"CertificateSigningRequest.__hash__  r{   r%   c                     dS r   r\   rH   s    r$   r   z$CertificateSigningRequest.public_key  r{   r%   c                     dS r   r\   rH   s    r$   r   z!CertificateSigningRequest.subject  r{   r%   c                     dS r   r\   rH   s    r$   r   z2CertificateSigningRequest.signature_hash_algorithm  r{   r%   c                     dS r   r\   rH   s    r$   r   z1CertificateSigningRequest.signature_algorithm_oid  r{   r%   c                     dS )z@
        Returns the extensions in the signing request.
        Nr\   rH   s    r$   r-   z$CertificateSigningRequest.extensions  r{   r%   c                     dS )z/
        Returns an Attributes object.
        Nr\   rH   s    r$   r2   z$CertificateSigningRequest.attributes
  r{   r%   r   c                     dS )z;
        Encodes the request to PEM or DER format.
        Nr\   r   s     r$   r   z&CertificateSigningRequest.public_bytes  r{   r%   c                     dS r   r\   rH   s    r$   r   z#CertificateSigningRequest.signature  r{   r%   c                     dS )zd
        Returns the PKCS#10 CertificationRequestInfo bytes as defined in RFC
        2986.
        Nr\   rH   s    r$   tbs_certrequest_bytesz/CertificateSigningRequest.tbs_certrequest_bytes  r{   r%   c                     dS )z8
        Verifies signature of signing request.
        Nr\   rH   s    r$   r   z,CertificateSigningRequest.is_signature_valid&  r{   r%   r   c                     dS )z:
        Get the attribute value for a given OID.
        Nr\   )r"   r   s     r$   re   z/CertificateSigningRequest.get_attribute_for_oid-  r{   r%   N)"r&   r'   r(   r   r   rZ   r[   rR   rX   rU   r   r   rY   r   r   rf   r   r   r   r   r   r   r   r-   r^   r2   r   r   rW   r   r   r   r   re   r\   r%   r$   r   r     s       F t    
 	#    
 	5    
      X
 	-	.    X )9     X
 J     X
 J     X
 	]%;     
 5     X
 u     X D     X
 	)9 e      r%   r   databackendc                 *    t          j        |           S r   )	rust_x509load_pem_x509_certificater   r   s     r$   r   r   9       .t444r%   c                 *    t          j        |           S r   )r   load_pem_x509_certificates)r   s    r$   r   r   ?  s    /555r%   c                 *    t          j        |           S r   )r   load_der_x509_certificater   s     r$   r   r   D  r   r%   c                 *    t          j        |           S r   )r   load_pem_x509_csrr   s     r$   r   r   K       &t,,,r%   c                 *    t          j        |           S r   )r   load_der_x509_csrr   s     r$   r   r   R  r   r%   c                 *    t          j        |           S r   )r   load_pem_x509_crlr   s     r$   r   r   Y  r   r%   c                 *    t          j        |           S r   )r   load_der_x509_crlr   s     r$   r   r   `  r   r%   c                   >   e Zd Zdg g fdej        e         dej        ee                  dej        ej	        e
eej        e         f                  fdZdedd fdZd	ed
edd fdZddde
dedej        e         dd fdZ	 ddedej        e         dej        defdZdS ) CertificateSigningRequestBuilderNsubject_namer-   r2   c                 0    || _         || _        || _        dS )zB
        Creates an empty X.509 certificate request (v1).
        N)_subject_namer   ra   )r"   r  r-   r2   s       r$   r!   z)CertificateSigningRequestBuilder.__init__g  s"     *%%r%   namer   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.N&The subject name may only be set once.)rO   r   	TypeErrorr  r/   r  r   ra   r"   r  s     r$   r  z-CertificateSigningRequestBuilder.subject_namev  s\     $%% 	;9:::)EFFF/$"D$4
 
 	
r%   extvalcriticalc                     t          |t                    st          d          t          |j        ||          }t          || j                   t          | j        | j        |gz   | j	                  S )zE
        Adds an X.509 extension to the certificate request.
        "extension must be an ExtensionType)
rO   r   r
  r   r   r1   r   r  r  ra   r"   r  r  r,   s       r$   add_extensionz.CertificateSigningRequestBuilder.add_extension  sw     &-00 	B@AAAfj(F;;	#It/?@@@/	{*
 
 	
r%   )_tagr   rB   r  c                n   t          |t                    st          d          t          |t                    st          d          |$t          |t                    st          d          t          || j                   ||j        }nd}t          | j	        | j
        | j        |||fgz             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)rO   r   r
  rW   r   r6   ra   rB   r  r  r   )r"   r   rB   r  tags        r$   add_attributez.CertificateSigningRequestBuilder.add_attribute  s     #/00 	?=>>>%'' 	31222JtY$?$?3444#C)9:::*CCC/eS 122
 
 	
r%   private_keyrv   r   c                 Z    | j         t          d          t          j        | ||          S )zF
        Signs the request using the requestor's private key.
        Nz/A CertificateSigningRequest must have a subject)r  r/   r   create_x509_csrr"   r  rv   r   s       r$   signz%CertificateSigningRequestBuilder.sign  s1     %NOOO({IFFFr%   r   )r&   r'   r(   rf   r   r   r   r   r   Tupler   rW   rX   r!   r  r[   r  r   r  r   _AllowedHashTypesAnyr   r  r\   r%   r$   r  r  f  s        /3<> & &od+& K	- 89& KL)5&/#2FFG
	& & & &

 

*L 

 

 

 


#
/3
	+
 
 
 
. ,0
 
 

 

 oi(
 
,
 
 
 
H #	G G5G ?#45G 	G
 
#G G G G G Gr%   r  c                      e Zd ZU ej        ee                  ed<   ddddddg fdej        e	         dej        e	         dej        e
         dej        e         dej        ej                 dej        ej                 d	ej        ee                  d
dfdZde	d
d fdZde	d
d fdZde
d
d fdZded
d fdZdej        d
d fdZdej        d
d fdZdeded
d fdZ	 ddedej        e         dej        d
efdZdS )CertificateBuilderr   Nissuer_namer  r   r}   r   r   r-   r   c                     t           j        | _        || _        || _        || _        || _        || _        || _        || _	        d S r   )
rl   ro   _version_issuer_namer  _public_keyr   _not_valid_before_not_valid_afterr   )r"   r   r  r   r}   r   r   r-   s           r$   r!   zCertificateBuilder.__init__  sK      
')%+!1 /%r%   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  N%The issuer name may only be set once.)rO   r   r
  r#  r/   r  r  r$  r   r%  r&  r   r  s     r$   r   zCertificateBuilder.issuer_name  sv     $%% 	;9:::(DE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  Nr	  )rO   r   r
  r  r/   r  r#  r$  r   r%  r&  r   r  s     r$   r  zCertificateBuilder.subject_name  sv     $%% 	;9:::)EFFF!"!
 
 	
r%   keyc           
      l   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        | j                  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.Nz$The public key may only be set once.)rO   r   DSAPublicKeyr   RSAPublicKeyr   EllipticCurvePublicKeyr
   Ed25519PublicKeyr	   Ed448PublicKeyr   X25519PublicKeyr   X448PublicKeyr
  r$  r/   r  r#  r  r   r%  r&  r   )r"   r*  s     r$   r   zCertificateBuilder.public_key  s       )($&"
 
 	 !   'CDDD!"!
 
 	
r%   numberc           	      T   t          |t                    st          d          | j        t	          d          |dk    rt	          d          |                                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.N'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.)rO   rX   r
  r   r/   
bit_lengthr  r#  r  r$  r%  r&  r   r"   r3  s     r$   r}   z CertificateBuilder.serial_number!  s     &#&& 	GEFFF*FGGGQ;;DEEE #%%H   ""!
 
 	
r%   r7   c           	      z   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 activation time.
        Expecting datetime object.Nz*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.)rO   r;   r
  r%  r/   r?   _EARLIEST_UTC_TIMEr&  r  r#  r  r$  r   r   r"   r7   s     r$   r   z#CertificateBuilder.not_valid_before<  s     $ 122 	:8999!-IJJJ)$//$$$$    ,8M1M1M   "!
 
 	
r%   c           	      z   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.
        r<  Nz)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.)rO   r;   r
  r&  r/   r?   r=  r%  r  r#  r  r$  r   r   r>  s     r$   r   z"CertificateBuilder.not_valid_after[  s     $ 122 	:8999 ,HIII)$//$$$#  
 ".t---   ""
 
 	
r%   r  r  c           
         t          |t                    st          d          t          |j        ||          }t          || j                   t          | j        | j	        | j
        | j        | j        | j        | j        |gz             S )z=
        Adds an X.509 extension to the certificate.
        r  )rO   r   r
  r   r   r1   r   r  r#  r  r$  r   r%  r&  r  s       r$   r  z CertificateBuilder.add_extension{  s     &-00 	B@AAAfj(F;;	#It/?@@@!"!	{*
 
 	
r%   r  rv   r   c                 6   | j         t          d          | j        t          d          | j        t          d          | j        t          d          | j        t          d          | j        t          d          t          j        | ||          S )zC
        Signs the certificate using the CA's private key.
        Nz&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 key)	r  r/   r#  r   r%  r&  r$  r   create_x509_certificater  s       r$   r  zCertificateBuilder.sign  s     %EFFF$EFFF&FGGG!)NOOO (MNNN#CDDD0{INNNr%   r   )r&   r'   r(   rf   r   r   r   __annotations__r   r   r   rX   r;   r!   r   r  r   r}   r   r   r[   r  r   r  r  ru   r  r\   r%   r$   r  r    sL        Y}56666 .2.2AE.2?C>B<>& &_T*& od+& O$=>	&
 s+& !/(*;<&  ):;& K	- 89& 
& & & &&
 
)= 
 
 
 
$
 
*> 
 
 
 
$#
&#
 
#
 #
 #
 #
J
C 
,@ 
 
 
 
6
%
	
 
 
 
>
H$5 
:N 
 
 
 
@
#
/3
	
 
 
 
4 #	O O5O ?#45O 	O
 
O O O O O Or%   r  c                      e Zd ZU ej        ee                  ed<   ej        e         ed<   dddg g fdej	        e
         dej	        ej                 dej	        ej                 dej        ee                  dej        e         f
d	Zde
d
d fdZdej        d
d fdZdej        d
d fdZdeded
d fdZded
d fdZ	 ddedej	        e         dej        d
efdZdS ) CertificateRevocationListBuilderr   _revoked_certificatesNr   r   r   r-   revoked_certificatesc                 L    || _         || _        || _        || _        || _        d S r   )r#  _last_update_next_updater   rF  )r"   r   r   r   r-   rG  s         r$   r!   z)CertificateRevocationListBuilder.__init__  s2     (''%%9"""r%   r   c                     t          |t                    st          d          | j        t	          d          t          || j        | j        | j        | j	                  S )Nr  r(  )
rO   r   r
  r#  r/   rE  rI  rJ  r   rF  )r"   r   s     r$   r   z,CertificateRevocationListBuilder.issuer_name  sj     +t,, 	;9:::(DEEE/&
 
 	
r%   c                 b   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 )Nr<  !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.)rO   r;   r
  rI  r/   r?   r=  rJ  rE  r#  r   rF  )r"   r   s     r$   r   z,CertificateRevocationListBuilder.last_update  s     +x'899 	:8999(@AAA0==+++M   ([4;L-L-LK   0&
 
 	
r%   c                 b   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 )Nr<  rM  rN  z8The next update date must be after the last update date.)rO   r;   r
  rJ  r/   r?   r=  rI  rE  r#  r   rF  )r"   r   s     r$   r   z,CertificateRevocationListBuilder.next_update  s     +x'899 	:8999(@AAA0==+++M   ([4;L-L-LJ   0&
 
 	
r%   r  r  c                     t          |t                    st          d          t          |j        ||          }t          || j                   t          | j        | j	        | j
        | j        |gz   | j                  S )zM
        Adds an X.509 extension to the certificate revocation list.
        r  )rO   r   r
  r   r   r1   r   rE  r#  rI  rJ  rF  r  s       r$   r  z.CertificateRevocationListBuilder.add_extension   s     &-00 	B@AAAfj(F;;	#It/?@@@/	{*&
 
 	
r%   revoked_certificatec                     t          |t                    st          d          t          | j        | j        | j        | j        | j        |gz             S )z8
        Adds a revoked certificate to the CRL.
        z)Must be an instance of RevokedCertificate)	rO   r   r
  rE  r#  rI  rJ  r   rF  )r"   rQ  s     r$   add_revoked_certificatez8CertificateRevocationListBuilder.add_revoked_certificate  sa     -/ABB 	IGHHH/&*=)>>
 
 	
r%   r  rv   r   c                     | j         t          d          | j        t          d          | j        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 time)r#  r/   rI  rJ  r   create_x509_crlr  s       r$   r  z%CertificateRevocationListBuilder.sign$  sa     $=>>>$ABBB$ABBB({IFFFr%   r   )r&   r'   r(   rf   r   r   r   rC  r   r   r   r;   r!   r   r   r   r[   r  rS  r   r  r  r   r  r\   r%   r$   rE  rE    s        Y}56666!;'9:::: .2:>:><>@B: :_T*: _X%67: _X%67	:
 K	- 89: %k*<=: : : :

	+
 
 
 

#,
	+
 
 
 
0
#,
	+
 
 
 
0
#
/3
	+
 
 
 
&
#5
	+
 
 
 
* #	G G5G ?#45G 	G
 
#G G G G G Gr%   rE  c            	           e Zd Zddg fdej        e         dej        ej                 dej        ee	                  fdZ
dedd fdZd	ej        dd fd
Zde	dedd fdZddej        defdZdS )RevokedCertificateBuilderNr}   r   r-   c                 0    || _         || _        || _        d S r   r   r   s       r$   r!   z"RevokedCertificateBuilder.__init__7  r   r%   r3  r   c                 $   t          |t                    st          d          | j        t	          d          |dk    rt	          d          |                                dk    rt	          d          t          || j        | j                  S )Nr5  r6  r   z$The serial number should be positiver7  r8  )	rO   rX   r
  r   r/   r9  rW  r   r   r:  s     r$   r}   z'RevokedCertificateBuilder.serial_numberA  s    &#&& 	GEFFF*FGGGQ;;CDDD #%%H   )D)4+;
 
 	
r%   r7   c                    t          |t          j                  st          d          | j        t	          d          t          |          }|t          k     rt	          d          t          | j        || j	                  S )Nr<  z)The revocation date may only be set once.z7The revocation date must be on or after 1950 January 1.)
rO   r;   r
  r   r/   r?   r=  rW  r   r   r>  s     r$   r   z)RevokedCertificateBuilder.revocation_dateS  s     $ 122 	:8999 ,HIII)$//$$$L   )t'7
 
 	
r%   r  r  c                     t          |t                    st          d          t          |j        ||          }t          || j                   t          | j        | j	        | j        |gz             S )Nr  )
rO   r   r
  r   r   r1   r   rW  r   r   r  s       r$   r  z'RevokedCertificateBuilder.add_extensionc  sw     &-00 	B@AAAfj(F;;	#It/?@@@(!	{*
 
 	
r%   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   r/   r   r   r   r   )r"   r   s     r$   buildzRevokedCertificateBuilder.buildq  sf    &NOOO (C   &!t'((
 
 	
r%   r   )r&   r'   r(   rf   r   rX   r;   r   r   r   r!   r}   r   r[   r  r  r   r]  r\   r%   r$   rW  rW  6  s        /3>B<>	& &s+&  ):;& K	- 89	& & & &
C 
,G 
 
 
 
$
%
	$
 
 
 
 
#
/3
	$
 
 
 

 
VZ 
3E 
 
 
 
 
 
r%   rW  c                  b    t                               t          j        d          d          dz	  S )N   bigr   )rX   
from_bytesosurandomr\   r%   r$   random_serial_numberrd    s#    >>"*R..%00A55r%   r   )Pr   r;   rb  rf   cryptographyr   "cryptography.hazmat.bindings._rustr   r   cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   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   r=  r   SHA224SHA256SHA384SHA512SHA3_224SHA3_256SHA3_384SHA3_512r  	Exceptionr   r   r1   r  rW   r   rX   r6   r?   rA   r^   Enumrl   rq   ABCMetaru   registerr   r   r   r   r  r   r   r   r   r   r   r   r  r  rE  rW  rd  r\   r%   r$   <module>ry     s5   


  				        @ @ @ @ @ @ @ @ @ @ @ @ @ @                          
            3 2 2 2 2 2 2 2 2 2 2 2 2 2&X&tQ22  L
M
M
M
M
O
O
O
O	     	   E'EIm45E 
E E E E	E		E%ufoc.BBC	E
 
	E 	E 	E 	EX%6 8;L    !8 !8 !8 !8 !8 !8 !8 !8HF F F F F F F F(    ej   
- - - - -Y - - -} } } } }CK } } } }B   Y* + + +    3;    0   I8 9 9 9         /      0y y y y y#+ y y y yx  " "9#F G G GY Y Y Y Y#+ Y Y Y Yz  " "9#F G G G
 (,5 5
5 *55 5 5 56U 6v{;/G 6 6 6 6 (,5 5
5 *55 5 5 5 (,- -
- *-- - - - (,- -
- *-- - - - (,- -
- *-- - - - (,- -
- *-- - - -YG YG YG YG YG YG YG YGxjO jO jO jO jO jO jO jOZDG DG DG DG DG DG DG DGNF
 F
 F
 F
 F
 F
 F
 F
R6c 6 6 6 6 6 6r%   