xtrace_sdk.x_vec.crypto.key_provider¶
Key provider abstractions for AES key management.
Defines a KeyProvider protocol and concrete implementations:
PassphraseKeyProvider: derives a 256-bit AES key from a passphrase using scrypt.AWSKMSKeyProvider: envelope encryption via AWS KMS — the data encryption key (DEK) is generated or unwrapped by KMS and never persisted in plaintext.
Attributes¶
Classes¶
Protocol for objects that supply a 256-bit AES key and can wrap/unwrap it for storage. |
|
Derives a 256-bit AES key from a passphrase using scrypt. |
|
Envelope encryption via AWS KMS. |
Module Contents¶
- xtrace_sdk.x_vec.crypto.key_provider._SCRYPT_N = 16384¶
- xtrace_sdk.x_vec.crypto.key_provider._SCRYPT_R = 8¶
- xtrace_sdk.x_vec.crypto.key_provider._SCRYPT_P = 1¶
- xtrace_sdk.x_vec.crypto.key_provider._KEY_LEN = 32¶
- xtrace_sdk.x_vec.crypto.key_provider._DEFAULT_SALT = b'xtrace-aes-gcm-v1'¶
- class xtrace_sdk.x_vec.crypto.key_provider.KeyProvider¶
Bases:
ProtocolProtocol for objects that supply a 256-bit AES key and can wrap/unwrap it for storage.
- wrap_key()¶
Return an opaque blob that can be stored alongside ciphertext to recover the key later.
- Return type:
- classmethod from_wrapped(wrapped, **kwargs)¶
Reconstruct a provider from a blob previously returned by
wrap_key().- Parameters:
wrapped (bytes)
kwargs (Any)
- Return type:
- class xtrace_sdk.x_vec.crypto.key_provider.PassphraseKeyProvider(passphrase, salt=None)¶
Derives a 256-bit AES key from a passphrase using scrypt.
This is the default key provider and preserves backwards-compatible behavior. The passphrase is never stored — only the derived key is kept in memory.
- _salt = b'xtrace-aes-gcm-v1'¶
- _key¶
- classmethod from_wrapped(wrapped, **kwargs)¶
Re-derive the key from the passphrase and stored salt.
- Parameters:
wrapped (bytes) – The salt bytes returned by
wrap_key().passphrase – The original passphrase (passed via kwargs).
kwargs (Any)
- Return type:
- class xtrace_sdk.x_vec.crypto.key_provider.AWSKMSKeyProvider(kms_client, key_id)¶
Envelope encryption via AWS KMS.
On creation, generates a random 256-bit DEK and wraps it with KMS. On load, unwraps a previously wrapped DEK using KMS.
Requires
boto3at runtime. The KMS key must grant the callerkms:Encryptandkms:Decryptpermissions.- Parameters:
- _kms¶
- _key_id¶
- classmethod create(kms_client, key_id)¶
Generate a fresh DEK via KMS
GenerateDataKey.- Parameters:
- Return type:
- classmethod from_wrapped(wrapped, **kwargs)¶
Unwrap a previously stored EDEK using KMS
Decrypt.- Parameters:
wrapped (bytes) – The EDEK bytes returned by
wrap_key().kms_client – A
boto3KMS client (passed via kwargs).key_id – KMS key ID, ARN, or alias (passed via kwargs).
kwargs (Any)
- Return type: