Encryption
Integrates encryption logic and key management. Uses the KeyStorageStrategy and EncryptionStrategy interfaces. Responsible for: - Retrieving the key for a given subject_id - Encrypting and decrypting data - Masking data when the key is not available (crypto-shredding) - Processing event encryption/decryption with field annotations
Source code in event_sourcery/_event_store/event/encryption.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
decrypt(event_type, raw, stream_id)
Decrypts all fields of the event marked as encrypted in the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type |
type[BaseModel]
|
The event class type. |
required |
raw |
dict[str, Any]
|
The raw event data with encrypted fields. |
required |
stream_id |
StreamId
|
The stream identifier used for subject resolution. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The event data with decrypted fields (or masked if no key). |
Source code in event_sourcery/_event_store/event/encryption.py
encrypt(event, stream_id)
Encrypts all fields of the event marked as encrypted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event |
BaseModel
|
The event instance to encrypt. |
required |
stream_id |
StreamId
|
The stream identifier used for subject resolution. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The event data with encrypted fields. |
Raises:
| Type | Description |
|---|---|
NoSubjectIdFound
|
If the subject id cannot be determined for encryption. |
KeyNotFoundError
|
If the encryption key for a subject is missing. |
Source code in event_sourcery/_event_store/event/encryption.py
shred(subject_id)
Deletes the encryption key for the given subject, effectively making all encrypted data for that subject unrecoverable (crypto-shredding).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id |
str
|
The subject identifier whose key should be deleted. |
required |