In memory (for dev)
In-Memory Storage is a simple key-value store that keeps data in memory. It is useful for testing and development purposes, but not suitable for production use due to its volatility.
InMemStorage
¶
Bases: CipherStorageProtocol
An in-memory implementation of the CipherStorageProtocol.
This class provides a simple, non-persistent storage mechanism using a Python dictionary. It is suitable for testing or scenarios where data persistence across sessions is not required.
Attributes:
Name | Type | Description |
---|---|---|
data |
dict[Hash, tuple[Ciphertext, Metadata]]
|
A dictionary to store ciphertexts and their associated metadata, keyed by a hash. |
Source code in topsecret/infra/storage/inmem.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
__init__()
¶
Initializes the InMemStorage.
Sets up an empty dictionary to hold the stored data.
Source code in topsecret/infra/storage/inmem.py
33 34 35 36 37 38 |
|
contains(key)
¶
Checks if a key exists in the storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Hash
|
The key to check for. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the key exists in the storage, False otherwise. |
Source code in topsecret/infra/storage/inmem.py
65 66 67 68 69 70 71 72 73 74 |
|
retrieve(key)
¶
Retrieves the ciphertext and metadata associated with a key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Hash
|
The key for which to retrieve the data. |
required |
Returns:
Type | Description |
---|---|
tuple[Ciphertext, Metadata]
|
tuple[Ciphertext, Metadata]: The stored ciphertext and metadata. |
Raises:
Type | Description |
---|---|
KeyError
|
If the key is not found in the storage. |
Source code in topsecret/infra/storage/inmem.py
51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
store(key, value)
¶
Stores a ciphertext and its metadata associated with a key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key under which to store the value. |
required |
value
|
tuple[Ciphertext, Metadata]
|
A tuple containing the ciphertext and its associated metadata. |
required |
Source code in topsecret/infra/storage/inmem.py
40 41 42 43 44 45 46 47 48 49 |
|