Ë
    (üàg¡"  ã                   óZ   — d dl Zd dl mZmZmZ d dlmZmZmZm	Z	  G d„ d«      Z
dd„Zd„ Zy)	é    N)Úceil_divÚbytes_to_longÚlong_to_bytes)ÚDerSequenceÚDerNullÚDerOctetStringÚDerObjectIdc                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚPKCS115_SigSchemez‚A signature object for ``RSASSA-PKCS1-v1_5``.
    Do not instantiate directly.
    Use :func:`Crypto.Signature.pkcs1_15.new`.
    c                 ó   — || _         y)a  Initialize this PKCS#1 v1.5 signature scheme object.

        :Parameters:
          rsa_key : an RSA key object
            Creation of signatures is only possible if this is a *private*
            RSA key. Verification of signatures is always possible.
        N)Ú_key)ÚselfÚrsa_keys     úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/Crypto/Signature/pkcs1_15.pyÚ__init__zPKCS115_SigScheme.__init__)   s   € ð ˆ�	ó    c                 ó6   — | j                   j                  «       S )z<Return ``True`` if this object can be used to sign messages.)r   Úhas_private)r   s    r   Úcan_signzPKCS115_SigScheme.can_sign3   s   € à�y‰y×$Ñ$Ó&Ð&r   c                 ó”  — t         j                  j                  j                  | j                  j
                  «      }t        |d«      }t        ||«      }t        |«      }| j                  j                  |«      }|t        t        |«      | j                  j                  | j                  j
                  «      k7  rt        d«      ‚|S )a€  Create the PKCS#1 v1.5 signature of a message.

        This function is also called ``RSASSA-PKCS1-V1_5-SIGN`` and
        it is specified in
        `section 8.2.1 of RFC8017 <https://tools.ietf.org/html/rfc8017#page-36>`_.

        :parameter msg_hash:
            This is an object from the :mod:`Crypto.Hash` package.
            It has been used to digest the message to sign.
        :type msg_hash: hash object

        :return: the signature encoded as a *byte string*.
        :raise ValueError: if the RSA key is not long enough for the given hash algorithm.
        :raise TypeError: if the RSA key has no private half.
        é   z+Fault detected in RSA private key operation)ÚCryptoÚUtilÚnumberÚsizer   Únr   Ú_EMSA_PKCS1_V1_5_ENCODEr   Ú_decrypt_to_bytesÚpowÚeÚ
ValueError)r   Úmsg_hashÚmodBitsÚkÚemÚem_intÚ	signatures          r   ÚsignzPKCS115_SigScheme.sign7   s–   € ô$ —+‘+×$Ñ$×)Ñ)¨$¯)©)¯+©+Ó6ˆÜ�W˜QÓˆô % X¨qÓ1ˆä˜rÓ"ˆà—I‘I×/Ñ/°Ó7ˆ	à”Sœ yÓ1°4·9±9·;±;ÀÇ	Á	ÇÁÓLÒLÜÐJÓKÐKØÐr   c                 ó.  — t         j                  j                  j                  | j                  j
                  «      }t        |d«      }t        |«      |k7  rt        d«      ‚t        |«      }| j                  j                  |«      }t        ||«      }	 t        ||d«      g}	 |j                  j                  d«      }	|	s|j!                  t        ||d«      «       ||vrt        d«      ‚y# t        $ r d}	Y Œ;w xY w# t        $ r t        d«      ‚w xY w)ax  Check if the  PKCS#1 v1.5 signature over a message is valid.

        This function is also called ``RSASSA-PKCS1-V1_5-VERIFY`` and
        it is specified in
        `section 8.2.2 of RFC8037 <https://tools.ietf.org/html/rfc8017#page-37>`_.

        :parameter msg_hash:
            The hash that was carried out over the message. This is an object
            belonging to the :mod:`Crypto.Hash` module.
        :type parameter: hash object

        :parameter signature:
            The signature that needs to be validated.
        :type signature: byte string

        :raise ValueError: if the signature is not valid.
        r   zInvalid signatureTz1.2.840.113549.2.FN)r   r   r   r   r   r   r   Úlenr!   r   Ú_encryptr   r   ÚoidÚ
startswithÚAttributeErrorÚappend)
r   r"   r'   r#   r$   Úsignature_intr&   Úem1Úpossible_em1Úalgorithm_is_mds
             r   ÚverifyzPKCS115_SigScheme.verifyW   s  € ô( —+‘+×$Ñ$×)Ñ)¨$¯)©)¯+©+Ó6ˆÜ�W˜aÓ ˆô ˆy‹>˜QÒÜÐ0Ó1Ð1ä% iÓ0ˆà—‘×#Ñ# MÓ2ˆä˜F AÓ&ˆð	2Ü4°X¸qÀ$ÓGÐIˆLð(Ø"*§,¡,×"9Ñ"9Ð:MÓ"N�ñ #Ø×#Ñ#Ô$;¸HÀaÈÓ$OÔPð �lÑ"ÜÐ0Ó1Ð1Øøô "ò (Ø"'’ð(ûô ò 	2ÜÐ0Ó1Ð1ð	2ús0   ÂC? Â%C. Ã C? Ã.C<Ã9C? Ã;C<Ã<C? Ã?DN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r(   r4   © r   r   r   r   #   s   „ ñò
ò'òó@4r   r   c                 óÜ  — t        t        | j                  «      j                  «       g«      }|r'|j	                  t        «       j                  «       «       t        | j                  «       «      }t        |j                  «       |j                  «       g«      j                  «       }|t        |«      dz   k  rt        dt        |«      z  «      ‚d|t        |«      z
  dz
  z  }d|z   dz   |z   S )aè  
    Implement the ``EMSA-PKCS1-V1_5-ENCODE`` function, as defined
    in PKCS#1 v2.1 (RFC3447, 9.2).

    ``_EMSA-PKCS1-V1_5-ENCODE`` actually accepts the message ``M`` as input,
    and hash it internally. Here, we expect that the message has already
    been hashed instead.

    :Parameters:
     msg_hash : hash object
            The hash object that holds the digest of the message being signed.
     emLen : int
            The length the final encoding must have, in bytes.
     with_hash_parameters : bool
            If True (default), include NULL parameters for the hash
            algorithm in the ``digestAlgorithm`` SEQUENCE.

    :attention: the early standard (RFC2313) stated that ``DigestInfo``
        had to be BER-encoded. This means that old signatures
        might have length tags in indefinite form, which
        is not supported in DER. Such encoding cannot be
        reproduced by this function.

    :Return: An ``emLen`` byte long string that encodes the hash.
    é   z3DigestInfo is too long for this RSA key (%d bytes).ó   ÿé   s    ó    )
r   r	   r,   Úencoder/   r   r   Údigestr*   Ú	TypeError)r"   ÚemLenÚwith_hash_parametersÚ
digestAlgor@   Ú
digestInfoÚPSs          r   r   r   Ž   sÙ   € ôd œ{¨8¯<©<Ó8×?Ñ?ÓAÐCÓD€JáØ×Ñœ'›)×*Ñ*Ó,Ô-ä  §¡Ó!2Ó3€FÜØ×%Ñ%Ó'Ø—M‘M“Oðó ÷ ‘v“xð ð ŒS�‹_˜RÑÒÜÐMÔPSÐT^ÓP_Ñ_Ó`Ð`Ø	�EœC 
›OÑ+¨aÑ/Ñ	0€BØ˜Ñ˜gÑ%¨
Ñ2Ð2r   c                 ó   — t        | «      S )a†  Create a signature object for creating
    or verifying PKCS#1 v1.5 signatures.

    :parameter rsa_key:
      The RSA key to use for signing or verifying the message.
      This is a :class:`Crypto.PublicKey.RSA` object.
      Signing is only possible when ``rsa_key`` is a **private** RSA key.
    :type rsa_key: RSA object

    :return: a :class:`PKCS115_SigScheme` signature object
    )r   )r   s    r   ÚnewrH   Ò   s   € ô ˜WÓ%Ð%r   )T)ÚCrypto.Util.numberr   r   r   r   ÚCrypto.Util.asn1r   r   r   r	   r   r   rH   r9   r   r   ú<module>rK      s/   ðó> ß EÑ Eß NÓ N÷hñ hóVB3óH&r   