ó 9(Zc@s“dZddlZddlmZddlmZddlmZeje ƒZ de fd„ƒYZ d „Z d e fd „ƒYZd „ZdS( s4Contains encryption primitives and helper functions.iÿÿÿÿN(tdefault_backend(tCipheri(t EncryptedDatat EncryptorcBs8eZdZd„Zd„Zd„Zed„ƒZRS(sHAbstract encryption handler. :param algorithm: Algorithm used to encrypt this body :type algorithm: aws_encryption_sdk.identifiers.Algorithm :param bytes key: Encryption key :param bytes associated_data: Associated Data to send to encryption subsystem :param bytes iv: IV to use when encrypting message cCs\||_||_t|j|ƒ|j|jƒdtƒƒjƒ|_|jj|ƒdS(sPrepares initial values.tbackendN( t source_keytivRtencryption_algorithmtencryption_modeRt encryptort _encryptortauthenticate_additional_data(tselft algorithmtkeytassociated_dataR((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyt__init__"s   cCs|jj|ƒS(s§Updates _encryptor with provided plaintext. :param bytes plaintext: Plaintext to encrypt :returns: Encrypted ciphertext :rtype: bytes (R tupdate(R t plaintext((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyR3scCs |jjƒS(smFinalizes and closes _encryptor. :returns: Final encrypted ciphertext :rtype: bytes (R tfinalize(R ((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyR<scCs |jjS(syReturns the _encryptor tag from the encryption subsystem. :returns: Encryptor tag :rtype: bytes (R ttag(R ((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyRDs(t__name__t __module__t__doc__RRRtpropertyR(((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyRs   cCsDt||||ƒ}|j|ƒ|jƒ}t|j||jƒS(sÈEncrypts a frame body. :param algorithm: Algorithm used to encrypt this body :type algorithm: aws_encryption_sdk.identifiers.Algorithm :param bytes key: Encryption key :param bytes plaintext: Body plaintext :param bytes associated_data: Body AAD Data :param bytes iv: IV to use when encrypting message :returns: Deserialized object containing encrypted body :rtype: aws_encryption_sdk.internal.structures.EncryptedData (RRRRRR(R RRRRR t ciphertext((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pytencryptNs t DecryptorcBs)eZdZd„Zd„Zd„ZRS(s™Abstract decryption handler. :param algorithm: Algorithm used to encrypt this body :type algorithm: aws_encryption_sdk.identifiers.Algorithm :param bytes key: Raw source key :param bytes associated_data: Associated Data to send to decryption subsystem :param bytes iv: IV value with which to initialize decryption subsystem :param bytes tag: Tag with which to validate ciphertext cCsS||_t|j|ƒ|j||ƒdtƒƒjƒ|_|jj|ƒdS(sPrepares initial values.RN(RRRRRt decryptort _decryptorR (R R RRRR((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyRjs   cCs|jj|ƒS(s©Updates _decryptor with provided ciphertext. :param bytes ciphertext: Ciphertext to decrypt :returns: Decrypted plaintext :rtype: bytes (RR(R R((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyRyscCs |jjƒS(slFinalizes and closes _decryptor. :returns: Final decrypted plaintext :rtype: bytes (RR(R ((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyR‚s(RRRRRR(((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyR_s   cCs8t||||j|jƒ}|j|jƒ|jƒS(sxDecrypts a frame body. :param algorithm: Algorithm used to encrypt this body :type algorithm: aws_encryption_sdk.identifiers.Algorithm :param bytes key: Plaintext data key :param encrypted_data: EncryptedData containing body data :type encrypted_data: :class:`aws_encryption_sdk.internal.structures.EncryptedData`, :class:`aws_encryption_sdk.internal.structures.FrameBody`, or :class:`aws_encryption_sdk.internal.structures.MessageNoFrameBody` :param bytes associated_data: AAD string generated for body :type associated_data: bytes :returns: Plaintext of body :rtype: bytes (RRRRRR(R Rtencrypted_dataRR((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pytdecrypt‹s(Rtloggingtcryptography.hazmat.backendsRt&cryptography.hazmat.primitives.ciphersRt structuresRt getLoggerRt_LOGGERtobjectRRRR(((sY/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/internal/crypto/encryption.pyt s 6 ,