ó 9(Zc@s(dZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z dd l mZdd lmZmZd „Zd „Zd „Zd„Zd„ZddZd„Zejdeƒdefd„ƒYƒZejdeƒdefd„ƒYƒZdS(sdCommon functions and structures for use in cryptographic materials caches. .. versionadded:: 1.3.0 iÿÿÿÿ(tLockN(tdefault_backend(thashesi(tNotSupportedError(tserialize_encryption_context(tserialize_encrypted_data_key(tDecryptionMaterialstEncryptionMaterialscCstjtjƒdtƒƒS(s~Builds a new instance of the hasher used for building cache keys. :rtype: cryptography.hazmat.primitives.hashes.Hash tbackend(RtHashtSHA512R(((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt_new_cache_key_hashers cCs|j|ƒ|jƒS(sGenerates the expected hash for the provided partition name. :param hasher: Existing hasher to use :type hasher: cryptography.hazmat.primitives.hashes.Hash :param bytes partition_name: Partition name to hash :returns: Complete hash :rtype: bytes (tupdatetfinalize(thashertpartition_name((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt_partition_name_hash)s cCs#t|ƒ}|j|ƒ|jƒS(sGenerates the expected hash for the provided encryption context. :param hasher: Existing hasher to use :type hasher: cryptography.hazmat.primitives.hashes.Hash :param dict encryption_context: Encryption context to hash :returns: Complete hash :rtype: bytes (RR R (Rtencryption_contexttserialized_encryption_context((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt_encryption_context_hash6s  cCsž|jdkrd}nd|jjƒ}tƒ}td|jƒd|ƒ}td|jƒd|jƒ}|j|ƒ|j|ƒ|j|ƒ|j ƒS(s,Generates a cache key for an encrypt request. :param bytes partition: Partition name for which to generate key :param request: Request for which to generate key :type request: aws_encryption_sdk.materials_managers.EncryptionMaterialsRequest :returns: cache key :rtype: bytes tsRRRN( t algorithmtNonet id_as_bytesR RtcopyRRR R (t partitiontrequestt_algorithm_infoRt_partition_hasht_ec_hash((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt$build_encryption_materials_cache_keyDs          cCsbg}xF|D]>}t|ƒ}|jƒ}|j|ƒ|j|jƒƒq Wdjt|ƒƒS(s<Generates the expected hash for the provided encrypted data keys. :param hasher: Existing hasher to use :type hasher: cryptography.hazmat.primitives.hashes.Hash :param iterable encrypted_data_keys: Encrypted data keys to hash :returns: Concatenated, sorted, list of all hashes :rtype: bytes t(RRR tappendR tjointsorted(Rtencrypted_data_keyst hashed_keystedktserialized_edkt_hasher((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt_encrypted_data_keys_hashbs     Ri@cCsºtƒ}td|jƒd|ƒ}|jjƒ}td|jƒd|jƒ}td|jƒd|jƒ}|j |ƒ|j |ƒ|j |ƒ|j t ƒ|j |ƒ|j ƒS(s+Generates a cache key for a decrypt request. :param bytes partition: Partition name for which to generate key :param request: Request for which to generate key :type request: aws_encryption_sdk.materials_managers.DecryptionMaterialsRequest :returns: cache key :rtype: bytes RRR#R( R RRRRR(R#RRR t _512_BIT_PADR (RRRRRt _edks_hashR((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt$build_decryption_materials_cache_keyxs"            thashtCryptoMaterialsCacheEntryHintscBs>eZdZejdddejjejje ƒƒƒZ RS(s¡Optional metadata to associate with cryptographic materials cache entries. :param float lifetime: Number of seconds to retain entry in cache (optional) tdefaultt validatorN( t__name__t __module__t__doc__tattrtibRt validatorstoptionalt instance_oftfloattlifetime(((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyR-˜s tCryptoMaterialsCacheEntrycBsÅeZdZejdejjeƒƒZejdejje e fƒƒZ ejdej e ƒdejjejje ƒƒƒZd„Zd„Zed„ƒZd„Zd„Zd„ZRS( s=Value and metadata store for cryptographic materials cache entries. :param bytes cache_key: Identifier for entries in cache :param value: Value to store in cache entry :param hints: Metadata to associate with entry (optional) :type hints: aws_encryption_sdk.caches.CryptoMaterialsCacheEntryHints R/R.cCsCtjƒ|_d|_d|_t|_tƒ|_t|_dS(sPrepares initial values.iN( ttimet creation_timetbytes_encryptedtmessages_encryptedtTruetvalidRt_lockt_init_completed(tself((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt__attrs_post_init__¶s     cCs7t|dƒrtdƒ‚ntt|ƒj||ƒS(sŸDisable setting of attributes after __attrs_post_init__ has run. This provides a bit more certainty that usage values have not been modified. RBs>Attributes may not be set on CryptoMaterialsCacheEntry objects(thasattrRtsuperR:t __setattr__(RCtnametvalue((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyRGÂscCstjƒ|jS(sLReturns this entry's current age in seconds. :rtype: float (R;R<(RC((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pytageÊscCs)|jjdkrtS|j|jjkS(sQDetermines if if this entry's lifetime has passed. :rtype: bool N(thintsR9RtFalseRJ(RC((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt is_too_oldÒscCsT|jEtt|ƒjd|jdƒtt|ƒjd|j|ƒWdQXdS(séUpdates this cache entry's usage metadata to reflect one more message of size `bytes_encrypted` having been encrypted with this entry. :param int bytes_encrypted: Number of bytes encrypted in registered use. R>iR=N(RARFR:RGR>R=(RCR=((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt$_update_with_message_bytes_encryptedÛs cCs-|jtt|ƒjdtƒWdQXdS(s#Marks a cache entry as invalidated.R@N(RARFR:RGRL(RC((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyt invalidateës (R0R1R2R3R4R5R7tbytest cache_keyRRRItFactoryR-R6RKRDRGtpropertyRJRMRNRO(((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyR:¥s$ !  (R2t threadingRR;R3tcryptography.hazmat.backendsRtcryptography.hazmat.primitivesRt exceptionsRt&internal.formatting.encryption_contextRtinternal.formatting.serializeRtmaterials_managersRRR RRRR(R)R+tsRLtobjectR-R:(((sN/tmp/pip-build-wDUJoH/aws-encryption-sdk/aws_encryption_sdk/caches/__init__.pyts(