HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/cryptography/x509/__pycache__/base.cpython-310.pyc
o

�hِ�	@spddlmZddlZddlZddlZddlZddlZddlmZddl	m
Zddlm
Z
mZddlmZmZmZmZmZmZmZmZddlmZmZmZddlmZmZmZm Z dd	l!m"Z"m#Z#dd
l$m%Z%e�ddd�Z&ej'e
j(e
j)e
j*e
j+e
j,e
j-e
j.e
j/fZ0Gd
d�de1�Z2d?dd�Z3d@dd�Z4dAdd �Z5Gd!d"�d"�Z6Gd#d$�d$�Z7Gd%d&�d&ej8�Z9Gd'd(�d(e1�Z:Gd)d*�d*ej;d+�Z<e<�=ej<�Gd,d-�d-ej;d+�Z>e>�=ej>�Gd.d/�d/e>�Z?Gd0d1�d1ej;d+�Z@e@�=ej@�Gd2d3�d3ej;d+�ZAeA�=ejA�ejBZBejCZCejDZDejEZEejFZFejGZGejHZHGd4d5�d5�ZIGd6d7�d7�ZJGd8d9�d9�ZKGd:d;�d;�ZLdBd=d>�ZMdS)C�)�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�eZdZd	�fdd�Z�ZS)
�AttributeNotFound�msg�str�oidr�return�Nonec�t��|�||_dS�N)�super�__init__r)�selfrr��	__class__��I/usr/local/CyberCP/lib/python3.10/site-packages/cryptography/x509/base.pyr$9�
zAttributeNotFound.__init__)rrrrrr ��__name__�
__module__�__qualname__r$�
__classcell__r(r(r&r)r8�r�	extension�Extension[ExtensionType]�
extensions�list[Extension[ExtensionType]]rr cCs"|D]}|j|jkrtd��qdS)Nz$This extension has already been set.)r�
ValueError)r1r3�er(r(r)�_reject_duplicate_extension>s
��r7rr�
attributes�0list[tuple[ObjectIdentifier, bytes, int | None]]cCs$|D]
\}}}||krtd��qdS)Nz$This attribute has already been set.)r5)rr8�attr_oid�_r(r(r)�_reject_duplicate_attributeHs
��r<�time�datetime.datetimecCs6|jdur|��}|r
|nt��}|jdd�|S|S)z�Normalizes 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)r=�offsetr(r(r)�_convert_to_naive_utc_timeRs

rFc@sXeZdZejjfdd	d
�Zeddd��Zedd
d��Zddd�Z	ddd�Z
ddd�ZdS) �	Attributerr�value�bytes�_type�intrr cC�||_||_||_dSr")�_oid�_valuerJ)r%rrHrJr(r(r)r$a�
zAttribute.__init__cC�|jSr")rM�r%r(r(r)rk�z
Attribute.oidcCrPr")rNrQr(r(r)rHorRzAttribute.valuercCsd|j�d|j�d�S)Nz<Attribute(oid=z, value=�)>)rrHrQr(r(r)�__repr__s�zAttribute.__repr__�other�object�boolcCs2t|t�stS|j|jko|j|jko|j|jkSr")�
isinstancerG�NotImplementedrrHrJ�r%rVr(r(r)�__eq__vs

�
�zAttribute.__eq__cCst|j|j|jf�Sr")�hashrrHrJrQr(r(r)�__hash__�szAttribute.__hash__N)rrrHrIrJrKrr �rr�rrI�rr�rVrWrrX�rrK)r,r-r.r�
UTF8StringrHr$�propertyrrTr\r^r(r(r(r)rG`s�



rGc@s8eZdZddd�Zed�\ZZZdd	d
�Zddd�Z	dS)�
Attributesr8�typing.Iterable[Attribute]rr cCst|�|_dSr")�list�_attributes)r%r8r(r(r)r$�szAttributes.__init__rircCsd|j�d�S)Nz<Attributes(rS)rirQr(r(r)rT�szAttributes.__repr__rrrGcCs.|D]}|j|kr
|Sqtd|�d�|��)NzNo z attribute was found)rr)r%r�attrr(r(r)�get_attribute_for_oid�s

�z Attributes.get_attribute_for_oidN)r8rgrr ra)rrrrG)
r,r-r.r$r�__len__�__iter__�__getitem__rTrkr(r(r(r)rf�s


rfc@seZdZdZdZdS)�Versionr�N)r,r-r.�v1�v3r(r(r(r)ro�srocr)
�InvalidVersionrr�parsed_versionrKrr cr!r")r#r$rt)r%rrtr&r(r)r$�r*zInvalidVersion.__init__)rrrtrKrr r+r(r(r&r)rs�r0rsc@s�eZdZejdBdd��ZeejdCdd	���ZeejdDdd���ZejdEdd��Z	eejdFdd���Z
eejdGdd���ZeejdGdd���ZeejdGdd���Z
eejdGdd���ZeejdHdd���ZeejdHdd ���ZeejdId"d#���ZeejdFd$d%���ZeejdJd'd(���ZeejdKd*d+���ZeejdLd,d-���ZeejdLd.d/���ZeejdLd0d1���ZejdMd5d6��ZejdCd7d8��ZejdNd;d<��ZejdOd?d@��ZdAS)P�Certificate�	algorithm�hashes.HashAlgorithmrrIcC�dS�z4
        Returns bytes using digest passed.
        Nr(�r%rvr(r(r)�fingerprint��zCertificate.fingerprintrKcCrx)z3
        Returns certificate serial number
        Nr(rQr(r(r)�
serial_number�r|zCertificate.serial_numberrocCrx)z1
        Returns the certificate version
        Nr(rQr(r(r)�version�r|zCertificate.versionrcCrx�z(
        Returns the public key
        Nr(rQr(r(r)�
public_key�r|zCertificate.public_keyrcCrx)zA
        Returns the ObjectIdentifier of the public key.
        Nr(rQr(r(r)�public_key_algorithm_oid�r|z$Certificate.public_key_algorithm_oidr>cCrx)z?
        Not before time (represented as UTC datetime)
        Nr(rQr(r(r)�not_valid_before�r|zCertificate.not_valid_beforecCrx)zK
        Not before time (represented as a non-naive UTC datetime)
        Nr(rQr(r(r)�not_valid_before_utc�r|z Certificate.not_valid_before_utccCrx)z>
        Not after time (represented as UTC datetime)
        Nr(rQr(r(r)�not_valid_after�r|zCertificate.not_valid_aftercCrx)zJ
        Not after time (represented as a non-naive UTC datetime)
        Nr(rQr(r(r)�not_valid_after_utc�r|zCertificate.not_valid_after_utcrcCrx)z1
        Returns the issuer name object.
        Nr(rQr(r(r)�issuer�r|zCertificate.issuercCrx�z2
        Returns the subject name object.
        Nr(rQr(r(r)�subject�r|zCertificate.subject�hashes.HashAlgorithm | NonecCrx�zt
        Returns a HashAlgorithm corresponding to the type of the digest signed
        in the certificate.
        Nr(rQr(r(r)�signature_hash_algorithm�r|z$Certificate.signature_hash_algorithmcCrx�zJ
        Returns the ObjectIdentifier of the signature algorithm.
        Nr(rQr(r(r)�signature_algorithm_oid�r|z#Certificate.signature_algorithm_oid�0None | padding.PSS | padding.PKCS1v15 | ec.ECDSAcCrx�z=
        Returns the signature algorithm parameters.
        Nr(rQr(r(r)�signature_algorithm_parametersr|z*Certificate.signature_algorithm_parametersrcCrx)z/
        Returns an Extensions object.
        Nr(rQr(r(r)r3	r|zCertificate.extensionscCrx�z.
        Returns the signature bytes.
        Nr(rQr(r(r)�	signaturer|zCertificate.signaturecCrx)zR
        Returns the tbsCertificate payload bytes as defined in RFC 5280.
        Nr(rQr(r(r)�tbs_certificate_bytesr|z!Certificate.tbs_certificate_bytescCrx)zh
        Returns the tbsCertificate payload bytes with the SCT list extension
        stripped.
        Nr(rQr(r(r)�tbs_precertificate_bytesr|z$Certificate.tbs_precertificate_bytesrVrWrXcCrx�z"
        Checks equality.
        Nr(r[r(r(r)r\&r|zCertificate.__eq__cCrx�z"
        Computes a hash.
        Nr(rQr(r(r)r^,r|zCertificate.__hash__�encoding�serialization.EncodingcCrx)zB
        Serializes the certificate to PEM or DER format.
        Nr(�r%r�r(r(r)�public_bytes2r|zCertificate.public_bytesr�r cCrx)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�r(r(r)�verify_directly_issued_by8r|z%Certificate.verify_directly_issued_byN�rvrwrrIrc)rro�rrr_�rr>�rr�rr��rr��rrr`rb�r�r�rrI)r�rurr )r,r-r.�abc�abstractmethodr{rer}r~r�r�r�r�r�r�r�r�r�r�r�r3r�r�r�r\r^r�r�r(r(r(r)ru�szru)�	metaclassc@s\eZdZeejddd���Zeejddd���Zeejddd	���Zeejddd���Z	d
S)�RevokedCertificaterrKcCrx)zG
        Returns the serial number of the revoked certificate.
        Nr(rQr(r(r)r}Fr|z RevokedCertificate.serial_numberr>cCrx)zH
        Returns the date of when this certificate was revoked.
        Nr(rQr(r(r)�revocation_dateMr|z"RevokedCertificate.revocation_datecCrx)zl
        Returns the date of when this certificate was revoked as a non-naive
        UTC datetime.
        Nr(rQr(r(r)�revocation_date_utcTr|z&RevokedCertificate.revocation_date_utcrcCrx)zW
        Returns an Extensions object containing a list of Revoked extensions.
        Nr(rQr(r(r)r3\r|zRevokedCertificate.extensionsNrcr�r�)
r,r-r.rer�r�r}r�r�r3r(r(r(r)r�Esr�c@sNeZdZddd�Zedd
d��Zeddd
��Zeddd��Zeddd��ZdS)�_RawRevokedCertificater}rKr�r>r3rcCrLr"��_serial_number�_revocation_date�_extensions�r%r}r�r3r(r(r)r$irOz_RawRevokedCertificate.__init__rcCrPr")r�rQr(r(r)r}srRz$_RawRevokedCertificate.serial_numbercCstjdtjdd�|jS)NukProperties that return a naïve datetime object have been deprecated. Please switch to revocation_date_utc.rp)�
stacklevel)�warnings�warnr�DeprecatedIn42r�rQr(r(r)r�ws�z&_RawRevokedCertificate.revocation_datecCs|jjtjjd�S)Nr?)r�rDrB�timezone�utcrQr(r(r)r��sz*_RawRevokedCertificate.revocation_date_utccCrPr")r�rQr(r(r)r3�rRz!_RawRevokedCertificate.extensionsN)r}rKr�r>r3rrcr�r�)	r,r-r.r$rer}r�r�r3r(r(r(r)r�hs

	r�c@s�eZdZejdFdd��ZejdGd	d
��ZejdHdd��ZeejdIdd���Z	eejdJdd���Z
eejdKdd���ZeejdLdd���ZeejdMdd���Z
eejdMdd ���ZeejdNd"d#���ZeejdNd$d%���ZeejdOd'd(���ZeejdPd)d*���ZeejdPd+d,���ZejdQd0d1��ZejdRd2d3��ZejdSd6d7��ZejdTd:d7��ZejdUd=d7��ZejdVd?d@��ZejdWdCdD��ZdES)X�CertificateRevocationListr�r�rrIcCrx)z:
        Serializes the CRL to PEM or DER format.
        Nr(r�r(r(r)r��r|z&CertificateRevocationList.public_bytesrvrwcCrxryr(rzr(r(r)r{�r|z%CertificateRevocationList.fingerprintr}rK�RevokedCertificate | NonecCrx)zs
        Returns an instance of RevokedCertificate or None if the serial_number
        is not in the CRL.
        Nr()r%r}r(r(r)�(get_revoked_certificate_by_serial_number�r|zBCertificateRevocationList.get_revoked_certificate_by_serial_numberr�cCrxr�r(rQr(r(r)r��r|z2CertificateRevocationList.signature_hash_algorithmrcCrxr�r(rQr(r(r)r��r|z1CertificateRevocationList.signature_algorithm_oidr�cCrxr�r(rQr(r(r)r��r|z8CertificateRevocationList.signature_algorithm_parametersrcCrx)zC
        Returns the X509Name with the issuer of this CRL.
        Nr(rQr(r(r)r��r|z CertificateRevocationList.issuer�datetime.datetime | NonecCrx)z?
        Returns the date of next update for this CRL.
        Nr(rQr(r(r)�next_update�r|z%CertificateRevocationList.next_updatecCrx)zc
        Returns the date of next update for this CRL as a non-naive UTC
        datetime.
        Nr(rQr(r(r)�next_update_utc�r|z)CertificateRevocationList.next_update_utcr>cCrx)z?
        Returns the date of last update for this CRL.
        Nr(rQr(r(r)�last_update�r|z%CertificateRevocationList.last_updatecCrx)zc
        Returns the date of last update for this CRL as a non-naive UTC
        datetime.
        Nr(rQr(r(r)�last_update_utc�r|z)CertificateRevocationList.last_update_utcrcCrx)zS
        Returns an Extensions object containing a list of CRL extensions.
        Nr(rQr(r(r)r3�r|z$CertificateRevocationList.extensionscCrxr�r(rQr(r(r)r��r|z#CertificateRevocationList.signaturecCrx)zO
        Returns the tbsCertList payload bytes as defined in RFC 5280.
        Nr(rQr(r(r)�tbs_certlist_bytes�r|z,CertificateRevocationList.tbs_certlist_bytesrVrWrXcCrxr�r(r[r(r(r)r\�r|z CertificateRevocationList.__eq__cCrx)z<
        Number of revoked certificates in the CRL.
        Nr(rQr(r(r)rl�r|z!CertificateRevocationList.__len__�idxr�cC�dSr"r(�r%r�r(r(r)rn�z%CertificateRevocationList.__getitem__�slice�list[RevokedCertificate]cCr�r"r(r�r(r(r)rnr��int | slice�-RevokedCertificate | list[RevokedCertificate]cCrx)zS
        Returns a revoked certificate (or slice of revoked certificates).
        Nr(r�r(r(r)rnr|�#typing.Iterator[RevokedCertificate]cCrx)z8
        Iterator over the revoked certificates
        Nr(rQr(r(r)rmr|z"CertificateRevocationList.__iter__r�rcCrx)zQ
        Verifies signature of revocation list against given public key.
        Nr()r%r�r(r(r)�is_signature_validr|z,CertificateRevocationList.is_signature_validNr�r�)r}rKrr�r�r_r�r�)rr�r�r�r`rbrc)r�rKrr�)r�r�rr�)r�r�rr�)rr�)r�rrrX)r,r-r.r�r�r�r{r�rer�r�r�r�r�r�r�r�r3r�r�r\rl�typing�overloadrnrmr�r(r(r(r)r��slr�c@seZdZejd.dd��Zejd/dd	��Zejd0dd��Zeejd1dd���Z	eejd2dd���Z
eejd3dd���Zeejd4dd���Zeejd5dd���Z
eejd6dd���Zejd7d"d#��Zeejd8d$d%���Zeejd8d&d'���Zeejd9d(d)���Zejd:d+d,��Zd-S);�CertificateSigningRequestrVrWrrXcCrxr�r(r[r(r(r)r\!r|z CertificateSigningRequest.__eq__rKcCrxr�r(rQr(r(r)r^'r|z"CertificateSigningRequest.__hash__rcCrxrr(rQr(r(r)r�-r|z$CertificateSigningRequest.public_keyrcCrxr�r(rQr(r(r)r�3r|z!CertificateSigningRequest.subjectr�cCrxr�r(rQr(r(r)r�:r|z2CertificateSigningRequest.signature_hash_algorithmrcCrxr�r(rQr(r(r)r�Dr|z1CertificateSigningRequest.signature_algorithm_oidr�cCrxr�r(rQr(r(r)r�Kr|z8CertificateSigningRequest.signature_algorithm_parametersrcCrx)z@
        Returns the extensions in the signing request.
        Nr(rQr(r(r)r3Tr|z$CertificateSigningRequest.extensionsrfcCrx)z/
        Returns an Attributes object.
        Nr(rQr(r(r)r8[r|z$CertificateSigningRequest.attributesr�r�rIcCrx)z;
        Encodes the request to PEM or DER format.
        Nr(r�r(r(r)r�br|z&CertificateSigningRequest.public_bytescCrxr�r(rQr(r(r)r�hr|z#CertificateSigningRequest.signaturecCrx)zd
        Returns the PKCS#10 CertificationRequestInfo bytes as defined in RFC
        2986.
        Nr(rQr(r(r)�tbs_certrequest_bytesor|z/CertificateSigningRequest.tbs_certrequest_bytescCrx)z8
        Verifies signature of signing request.
        Nr(rQr(r(r)r�wr|z,CertificateSigningRequest.is_signature_validrcCrx)z:
        Get the attribute value for a given OID.
        Nr()r%rr(r(r)rk~r|z/CertificateSigningRequest.get_attribute_for_oidNrbrcr�r�r�r_r�r�)rrfr�r`)rrX)rrrrI)r,r-r.r�r�r\r^r�rer�r�r�r�r3r8r�r�r�r�rkr(r(r(r)r� sLr�c@sVeZdZdggfd*dd	�Zd+d
d�Zd,dd�Zdd�d-dd�Z	d.dd�d/d(d)�ZdS)0� CertificateSigningRequestBuilderN�subject_name�Name | Noner3r4r8r9cCs||_||_||_dS)zB
        Creates an empty X.509 certificate request (v1).
        N)�
_subject_namer�ri)r%r�r3r8r(r(r)r$�s	
z)CertificateSigningRequestBuilder.__init__�namerrcCs4t|t�s	td��|jdurtd��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.)rYr�	TypeErrorr�r5r�r�ri�r%r�r(r(r)r��s


�z-CertificateSigningRequestBuilder.subject_name�extvalr�criticalrXcCsFt|t�s	td��t|j||�}t||j�t|jg|j�|�|j	�S)zE
        Adds an X.509 extension to the certificate request.
        �"extension must be an ExtensionType)
rYrr�rrr7r�r�r�ri�r%r�r�r1r(r(r)�
add_extension�s
�z.CertificateSigningRequestBuilder.add_extension)�_tagrrrHrIr��_ASN1Type | NonecCs~t|t�s	td��t|t�std��|durt|t�std��t||j�|dur-|j}nd}t|j	|j
g|j�|||f��S)zK
        Adds an X.509 attribute with an OID and associated value.
        zoid must be an ObjectIdentifierzvalue must be bytesNztag must be _ASN1Type)rYrr�rIrr<rirHr�r�r�)r%rrHr��tagr(r(r)�
add_attribute�s


�z.CertificateSigningRequestBuilder.add_attribute��rsa_padding�private_keyrrv�_AllowedHashTypes | None�backend�
typing.Anyr��%padding.PSS | padding.PKCS1v15 | Noner�cCsX|jdur	td��|dur$t|tjtjf�std��t|tj�s$td��t	�
||||�S)zF
        Signs the request using the requestor's private key.
        Nz/A CertificateSigningRequest must have a subject�Padding must be PSS or PKCS1v15�&Padding is only supported for RSA keys)r�r5rYr�PSS�PKCS1v15r�r�
RSAPrivateKey�	rust_x509�create_x509_csr�r%r�rvr�r�r(r(r)�sign�s
�z%CertificateSigningRequestBuilder.sign)r�r�r3r4r8r9)r�rrr�)r�rr�rXrr�)rrrHrIr�r�rr�r")
r�rrvr�r�r�r�r�rr�)r,r-r.r$r�r�r�r�r(r(r(r)r��s�

�$��r�c@s�eZdZUded<ddddddgfd9dd�Zd:dd�Zd:dd�Zd;dd�Zd<dd �Zd=d#d$�Z	d=d%d&�Z
d>d+d,�Z	d?dd-�d@d7d8�ZdS)A�CertificateBuilderr4r�N�issuer_namer�r�r�� CertificatePublicKeyTypes | Noner}�
int | Noner�r�r�r3rr cCs6tj|_||_||_||_||_||_||_||_	dSr")
rorr�_version�_issuer_namer��_public_keyr��_not_valid_before�_not_valid_afterr�)r%r�r�r�r}r�r�r3r(r(r)r$�s

zCertificateBuilder.__init__r�rcCsDt|t�s	td��|jdurtd��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.)rYrr�r�r5r�r�r�r�r�r�r�r�r(r(r)r�s

�zCertificateBuilder.issuer_namecCsDt|t�s	td��|jdurtd��t|j||j|j|j	|j
|j�S)z:
        Sets the requestor's distinguished name.
        r�Nr�)rYrr�r�r5r�r�r�r�r�r�r�r�r(r(r)r�"s

�zCertificateBuilder.subject_name�keyrc	Cs`t|tjtjtjtjt	j
tjt
jf�std��|jdur td��t|j|j||j|j|j|j�S)zT
        Sets the requestor's public key (as found in the signing request).
        z�Expecting one of DSAPublicKey, RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey, Ed448PublicKey, X25519PublicKey, or X448PublicKey.Nz$The public key may only be set once.)rYr�DSAPublicKeyr�RSAPublicKeyr�EllipticCurvePublicKeyr
�Ed25519PublicKeyr	�Ed448PublicKeyr�X25519PublicKeyr
�
X448PublicKeyr�r�r5r�r�r�r�r�r�r�)r%r�r(r(r)r�4s2���
�zCertificateBuilder.public_key�numberrKcCsht|t�s	td��|jdurtd��|dkrtd��|��dkr$td��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.rz%The serial number should be positive.��3The serial number should not be more than 159 bits.)
rYrKr�r�r5�
bit_lengthr�r�r�r�r�r�r��r%rr(r(r)r}Ys&

��z CertificateBuilder.serial_numberr=r>cCszt|tj�s
td��|jdurtd��t|�}|tkrtd��|jdur-||jkr-td��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.)rYrBr�r�r5rF�_EARLIEST_UTC_TIMEr�r�r�r�r�r�r��r%r=r(r(r)r�ts,
���z#CertificateBuilder.not_valid_beforecCszt|tj�s
td��|jdurtd��t|�}|tkrtd��|jdur-||jkr-td��t|j	|j
|j|j|j||j
�S)z7
        Sets the certificate expiration time.
        rNz)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.)rYrBr�r�r5rFr	r�r�r�r�r�r�r�r
r(r(r)r��s.
�

��z"CertificateBuilder.not_valid_afterr�rr�rXc	CsVt|t�s	td��t|j||�}t||j�t|j|j	|j
|j|j|j
g|j�|��S)z=
        Adds an X.509 extension to the certificate.
        r�)rYrr�rrr7r�r�r�r�r�r�r�r�r�r(r(r)r��s
�z CertificateBuilder.add_extensionr�r�rrvr�r�r�r�r�rucCs�|jdur	td��|jdurtd��|jdurtd��|jdur$td��|jdur-td��|jdur6td��|durQt|tj	tj
f�sGtd��t|tj
�sQtd	��t�||||�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 keyr�r�)r�r5r�r�r�r�r�rYrr�r�r�rr�r��create_x509_certificater�r(r(r)r��s(





�zCertificateBuilder.sign)r�r�r�r�r�r�r}r�r�r�r�r�r3r4rr )r�rrr�)r�rrr�)rrKrr�)r=r>rr�)r�rr�rXrr�r")
r�rrvr�r�r�r�r�rru)
r,r-r.�__annotations__r$r�r�r�r}r�r�r�r�r(r(r(r)r��s*
�



%


 ��r�c@szeZdZUded<ded<dddggfd.d
d�Zd/dd�Zd0dd�Zd1dd�Zd2dd�Zd3d d!�Z		d4dd"�d5d,d-�Z
dS)6� CertificateRevocationListBuilderr4r�r��_revoked_certificatesNr�r�r�r�r�r3�revoked_certificatescCs"||_||_||_||_||_dSr")r��_last_update�_next_updater�r)r%r�r�r�r3rr(r(r)r$�s

z)CertificateRevocationListBuilder.__init__rrcCs<t|t�s	td��|jdurtd��t||j|j|j|j	�S)Nr�r�)
rYrr�r�r5r
rrr�r)r%r�r(r(r)r�s

�z,CertificateRevocationListBuilder.issuer_namer>cCsrt|tj�s
td��|jdurtd��t|�}|tkrtd��|jdur-||jkr-td��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.)rYrBr�rr5rFr	rr
r�r�r)r%r�r(r(r)r�s(
���z,CertificateRevocationListBuilder.last_updatecCsrt|tj�s
td��|jdurtd��t|�}|tkrtd��|jdur-||jkr-td��t|j	|j||j
|j�S)Nrrrz8The next update date must be after the last update date.)rYrBr�rr5rFr	rr
r�r�r)r%r�r(r(r)r�(s(
���z,CertificateRevocationListBuilder.next_updater�rr�rXcCsNt|t�s	td��t|j||�}t||j�t|j|j	|j
g|j�|�|j�S)zM
        Adds an X.509 extension to the certificate revocation list.
        r�)rYrr�rrr7r�r
r�rrrr�r(r(r)r�@s
�z.CertificateRevocationListBuilder.add_extension�revoked_certificater�cCs4t|t�s	td��t|j|j|j|jg|j�|��S)z8
        Adds a revoked certificate to the CRL.
        z)Must be an instance of RevokedCertificate)	rYr�r�r
r�rrr�r)r%rr(r(r)�add_revoked_certificateSs
�z8CertificateRevocationListBuilder.add_revoked_certificater�r�rrvr�r�r�r�r�r�cCs||jdur	td��|jdurtd��|jdurtd��|dur6t|tjtjf�s,td��t|t	j
�s6td��t�||||�S)NzA CRL must have an issuer namez"A CRL must have a last update timez"A CRL must have a next update timer�r�)
r�r5rrrYrr�r�r�rr�r��create_x509_crlr�r(r(r)r�ds


�z%CertificateRevocationListBuilder.sign)
r�r�r�r�r�r�r3r4rr�)r�rrr
)r�r>rr
)r�r>rr
)r�rr�rXrr
)rr�rr
r")
r�rrvr�r�r�r�r�rr�)r,r-r.rr$r�r�r�r�rr�r(r(r(r)r
�s$
�




��r
c@sHeZdZddgfddd	�Zdd
d�Zd dd�Zd!dd�Zd"d#dd�ZdS)$�RevokedCertificateBuilderNr}r�r�r�r3r4cCrLr"r�r�r(r(r)r$�rOz"RevokedCertificateBuilder.__init__rrKrcCsXt|t�s	td��|jdurtd��|dkrtd��|��dkr$td��t||j|j�S)Nrrrz$The serial number should be positiverr)	rYrKr�r�r5rrr�r�rr(r(r)r}�s

�
�z'RevokedCertificateBuilder.serial_numberr=r>cCsNt|tj�s
td��|jdurtd��t|�}|tkrtd��t|j||j	�S)Nrz)The revocation date may only be set once.z7The revocation date must be on or after 1950 January 1.)
rYrBr�r�r5rFr	rr�r�r
r(r(r)r��s
�
�z)RevokedCertificateBuilder.revocation_dater�rr�rXcCsFt|t�s	td��t|j||�}t||j�t|j|j	g|j�|��S)Nr�)
rYrr�rrr7r�rr�r�r�r(r(r)r��s
�z'RevokedCertificateBuilder.add_extensionr�r�r�cCs:|jdur	td��|jdurtd��t|j|jt|j��S)Nz/A revoked certificate must have a serial numberz1A revoked certificate must have a revocation date)r�r5r�r�rr�)r%r�r(r(r)�build�s

��zRevokedCertificateBuilder.build)r}r�r�r�r3r4)rrKrr)r=r>rr)r�rr�rXrrr")r�r�rr�)r,r-r.r$r}r�r�rr(r(r(r)r�s�



rrKcCst�t�d�d�d?S)N��bigr)rK�
from_bytes�os�urandomr(r(r(r)�random_serial_number�rUr)r1r2r3r4rr )rrr8r9rr )r=r>rr>rc)N�
__future__rr�rBrr�r��cryptographyr�"cryptography.hazmat.bindings._rustrr��cryptography.hazmat.primitivesrr�)cryptography.hazmat.primitives.asymmetricrrr	r
rrr
r�/cryptography.hazmat.primitives.asymmetric.typesrrr�cryptography.x509.extensionsrrrr�cryptography.x509.namerr�cryptography.x509.oidrr	�Union�SHA224�SHA256�SHA384�SHA512�SHA3_224�SHA3_256�SHA3_384�SHA3_512�_AllowedHashTypes�	Exceptionrr7r<rFrGrf�Enumrors�ABCMetaru�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�r
rrr(r(r(r)�<module>sv(
��




$  "fevI