Full Module Index
adk_secure_sessions ¶
Encrypted session storage for Google ADK.
Provides field-level encryption for ADK session data via pluggable encryption backends that conform to the EncryptionBackend protocol.
| ATTRIBUTE | DESCRIPTION |
|---|---|
EncryptionBackend | Protocol defining the encrypt/decrypt contract. TYPE: |
AesGcmBackend | AES-256-GCM authenticated encryption backend. TYPE: |
FernetBackend | Fernet symmetric encryption backend. TYPE: |
EncryptedSessionService | Encrypted session service wrapping TYPE: |
SecureSessionError | Base exception for all library errors. TYPE: |
EncryptionError | Raised when encryption fails. TYPE: |
DecryptionError | Raised when decryption fails. TYPE: |
SerializationError | Raised when data cannot be serialized to JSON. TYPE: |
ConfigurationError | Raised when the service is misconfigured at startup. TYPE: |
encrypt_session | Serialize a dict to an encrypted envelope. TYPE: |
decrypt_session | Decrypt an envelope back to a dict. TYPE: |
encrypt_json | Encrypt a JSON string into an envelope. TYPE: |
decrypt_json | Decrypt an envelope back to a JSON string. TYPE: |
BACKEND_AES_GCM | Backend identifier for AES-256-GCM encryption. TYPE: |
BACKEND_FERNET | Backend identifier for Fernet encryption. TYPE: |
ENVELOPE_VERSION_1 | Current envelope format version byte. TYPE: |
Examples:
Encrypt and decrypt session state:
from adk_secure_sessions import (
FernetBackend,
encrypt_session,
decrypt_session,
BACKEND_FERNET,
)
backend = FernetBackend("my-secret-passphrase")
envelope = await encrypt_session({"ssn": "123-45-6789"}, backend, BACKEND_FERNET)
state = await decrypt_session(envelope, backend)
See Also
adk_secure_sessions.protocols: Full protocol definition and known limitations.
BACKEND_AES_GCM module-attribute ¶
Backend identifier for AES-256-GCM encryption.
ENVELOPE_VERSION_1 module-attribute ¶
Current envelope format version byte.
AesGcmBackend ¶
AES-256-GCM encryption backend conforming to EncryptionBackend.
Accepts a key as exactly 32 bytes (256 bits). Use AESGCM.generate_key(bit_length=256) to generate a valid key.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_aesgcm | Internal AESGCM instance for encrypt/decrypt operations. TYPE: |
Examples:
Initialize with a generated key:
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
key = AESGCM.generate_key(bit_length=256)
backend = AesGcmBackend(key=key)
Source code in src/adk_secure_sessions/backends/aes_gcm.py
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 | |
backend_id property ¶
Unique backend identifier for the envelope header.
| RETURNS | DESCRIPTION |
|---|---|
int |
|
__init__ ¶
Initialize AesGcmBackend with the given key.
| PARAMETER | DESCRIPTION |
|---|---|
key | Encryption key as exactly 32 bytes (256 bits). TYPE: |
| RAISES | DESCRIPTION |
|---|---|
ConfigurationError | If key is not |
Source code in src/adk_secure_sessions/backends/aes_gcm.py
sync_encrypt ¶
Encrypt plaintext bytes synchronously.
Generates a fresh 12-byte random nonce per call. Returns nonce || ciphertext + tag.
| PARAMETER | DESCRIPTION |
|---|---|
plaintext | Raw bytes to encrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted bytes as |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If plaintext is not |
Examples:
Source code in src/adk_secure_sessions/backends/aes_gcm.py
sync_decrypt ¶
Decrypt ciphertext bytes synchronously.
Expects nonce (12 bytes) || ciphertext + tag.
| PARAMETER | DESCRIPTION |
|---|---|
ciphertext | Encrypted bytes to decrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Decrypted plaintext as bytes. |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If ciphertext is not |
DecryptionError | If decryption fails due to wrong key, tampered ciphertext, or malformed input. |
Examples:
Source code in src/adk_secure_sessions/backends/aes_gcm.py
encrypt async ¶
Encrypt plaintext bytes asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
plaintext | Raw bytes to encrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted bytes as |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If plaintext is not |
Examples:
Source code in src/adk_secure_sessions/backends/aes_gcm.py
decrypt async ¶
Decrypt ciphertext bytes asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
ciphertext | Encrypted bytes to decrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Decrypted plaintext as bytes. |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If ciphertext is not |
DecryptionError | If decryption fails due to wrong key, tampered ciphertext, or malformed input. |
Examples:
Source code in src/adk_secure_sessions/backends/aes_gcm.py
FernetBackend ¶
Fernet encryption backend conforming to EncryptionBackend.
Accepts a key as str or bytes. If the key is a valid base64url-encoded 32-byte Fernet key, it is used directly (no derivation, no salt marker). Otherwise, a two-phase key derivation scheme is used:
- Init: PBKDF2-HMAC-SHA256 (600,000 iterations) derives a master key from the passphrase.
- Per-operation: HKDF-SHA256 with a fresh random salt expands the master key into a unique per-operation Fernet key.
Backward compatibility: data encrypted with pre-3.2 fixed-salt derivation (480,000 iterations) is detected via marker byte and decrypted transparently.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_passphrase_key | Master key from PBKDF2 at 600k iterations (passphrase mode only, TYPE: |
_legacy_fernet | Fernet instance for direct-key mode or legacy (480k iterations) backward-compatible decryption. TYPE: |
_is_passphrase_mode | Whether the backend was initialized with a passphrase (True) or a pre-generated Fernet key (False). TYPE: |
Examples:
Initialize with a passphrase:
Initialize with a pre-generated Fernet key:
Source code in src/adk_secure_sessions/backends/fernet.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
backend_id property ¶
Unique backend identifier for the envelope header.
| RETURNS | DESCRIPTION |
|---|---|
int |
|
__init__ ¶
Initialize FernetBackend with the given key.
| PARAMETER | DESCRIPTION |
|---|---|
key | Encryption key as TYPE: |
| RAISES | DESCRIPTION |
|---|---|
ConfigurationError | If key is not |
Source code in src/adk_secure_sessions/backends/fernet.py
sync_encrypt ¶
Encrypt plaintext bytes synchronously.
In passphrase mode, generates a fresh 16-byte random salt, derives a per-operation Fernet key via HKDF, and returns SALT_MARKER || salt || fernet_token. In direct-key mode, returns a standard Fernet token.
| PARAMETER | DESCRIPTION |
|---|---|
plaintext | Raw bytes to encrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted ciphertext as bytes. |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If plaintext is not |
Examples:
Source code in src/adk_secure_sessions/backends/fernet.py
sync_decrypt ¶
Decrypt ciphertext bytes synchronously.
Detects the ciphertext format via the first byte:
0x01: new salted format — extracts salt, derives per-op key via HKDF, decrypts the Fernet token.>= 0x2B: legacy Fernet token — decrypts with the legacy Fernet instance.- Otherwise: raises
DecryptionError.
| PARAMETER | DESCRIPTION |
|---|---|
ciphertext | Encrypted bytes to decrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Decrypted plaintext as bytes. |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If ciphertext is not |
DecryptionError | If decryption fails due to wrong key, tampered ciphertext, or malformed input. |
Examples:
Source code in src/adk_secure_sessions/backends/fernet.py
encrypt async ¶
Encrypt plaintext bytes asynchronously.
Delegates to sync_encrypt via asyncio.to_thread().
| PARAMETER | DESCRIPTION |
|---|---|
plaintext | Raw bytes to encrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted ciphertext as bytes. |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If plaintext is not |
Examples:
Source code in src/adk_secure_sessions/backends/fernet.py
decrypt async ¶
Decrypt ciphertext bytes asynchronously.
Delegates to sync_decrypt via asyncio.to_thread().
| PARAMETER | DESCRIPTION |
|---|---|
ciphertext | Encrypted bytes to decrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Decrypted plaintext as bytes. |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If ciphertext is not |
DecryptionError | If decryption fails due to wrong key, tampered ciphertext, or malformed input. |
Examples:
Source code in src/adk_secure_sessions/backends/fernet.py
ConfigurationError ¶
Bases: SecureSessionError
flowchart TD
adk_secure_sessions.ConfigurationError[ConfigurationError]
adk_secure_sessions.exceptions.SecureSessionError[SecureSessionError]
adk_secure_sessions.exceptions.SecureSessionError --> adk_secure_sessions.ConfigurationError
click adk_secure_sessions.ConfigurationError href "" "adk_secure_sessions.ConfigurationError"
click adk_secure_sessions.exceptions.SecureSessionError href "" "adk_secure_sessions.exceptions.SecureSessionError"
Raised when the service is misconfigured at startup.
Covers invalid encryption keys, backends that do not conform to the EncryptionBackend protocol, invalid backend IDs, empty database paths, and database connection failures. Error messages never include key material or other sensitive data.
Examples:
Handle configuration failures at startup:
try:
service = EncryptedSessionService(
db_url="sqlite+aiosqlite:///sessions.db",
backend=my_backend,
)
except ConfigurationError as exc:
log.error("Service misconfigured: %s", exc)
Source code in src/adk_secure_sessions/exceptions.py
DecryptionError ¶
Bases: SecureSessionError, DontWrapMixin
flowchart TD
adk_secure_sessions.DecryptionError[DecryptionError]
adk_secure_sessions.exceptions.SecureSessionError[SecureSessionError]
adk_secure_sessions.exceptions.SecureSessionError --> adk_secure_sessions.DecryptionError
click adk_secure_sessions.DecryptionError href "" "adk_secure_sessions.DecryptionError"
click adk_secure_sessions.exceptions.SecureSessionError href "" "adk_secure_sessions.exceptions.SecureSessionError"
Raised when decryption fails.
Inherits DontWrapMixin so SQLAlchemy propagates this directly instead of wrapping it in StatementError.
Possible causes include a wrong key, tampered ciphertext, or malformed input. Error messages intentionally exclude key material, ciphertext, and plaintext to prevent information leakage.
Examples:
Handle decryption failures specifically:
try:
plaintext = await backend.decrypt(ciphertext)
except DecryptionError:
log.error("Decryption failed, check key")
Source code in src/adk_secure_sessions/exceptions.py
EncryptionError ¶
Bases: SecureSessionError, DontWrapMixin
flowchart TD
adk_secure_sessions.EncryptionError[EncryptionError]
adk_secure_sessions.exceptions.SecureSessionError[SecureSessionError]
adk_secure_sessions.exceptions.SecureSessionError --> adk_secure_sessions.EncryptionError
click adk_secure_sessions.EncryptionError href "" "adk_secure_sessions.EncryptionError"
click adk_secure_sessions.exceptions.SecureSessionError href "" "adk_secure_sessions.exceptions.SecureSessionError"
Raised when encryption fails.
Inherits DontWrapMixin so SQLAlchemy propagates this directly instead of wrapping it in StatementError.
Possible causes include invalid plaintext input or backend-specific errors. Error messages intentionally exclude key material, plaintext, and ciphertext to prevent information leakage.
Examples:
Handle encryption failures specifically:
try:
ciphertext = await backend.encrypt(plaintext)
except EncryptionError:
log.error("Encryption failed")
Source code in src/adk_secure_sessions/exceptions.py
SecureSessionError ¶
Bases: Exception
flowchart TD
adk_secure_sessions.SecureSessionError[SecureSessionError]
click adk_secure_sessions.SecureSessionError href "" "adk_secure_sessions.SecureSessionError"
Base exception for all adk-secure-sessions errors.
All library-specific exceptions inherit from this class so callers can use a single except SecureSessionError clause to handle any failure originating from this package.
Examples:
Catch any library error regardless of type:
try:
await backend.encrypt(plaintext)
except SecureSessionError:
log.error("adk-secure-sessions operation failed")
Source code in src/adk_secure_sessions/exceptions.py
SerializationError ¶
Bases: SecureSessionError, DontWrapMixin
flowchart TD
adk_secure_sessions.SerializationError[SerializationError]
adk_secure_sessions.exceptions.SecureSessionError[SecureSessionError]
adk_secure_sessions.exceptions.SecureSessionError --> adk_secure_sessions.SerializationError
click adk_secure_sessions.SerializationError href "" "adk_secure_sessions.SerializationError"
click adk_secure_sessions.exceptions.SecureSessionError href "" "adk_secure_sessions.exceptions.SecureSessionError"
Raised when data cannot be serialized to JSON.
Inherits DontWrapMixin so SQLAlchemy propagates this directly instead of wrapping it in StatementError.
This indicates a caller bug — the input contains types that are not JSON-serializable (e.g., datetime, custom objects). This is distinct from encryption/decryption failures which indicate configuration or data integrity issues.
Examples:
Handle serialization failures:
try:
envelope = await encrypt_session(data, backend, backend_id)
except SerializationError:
log.error("Data contains non-JSON-serializable values")
Source code in src/adk_secure_sessions/exceptions.py
EncryptionBackend ¶
Bases: Protocol
flowchart TD
adk_secure_sessions.EncryptionBackend[EncryptionBackend]
click adk_secure_sessions.EncryptionBackend href "" "adk_secure_sessions.EncryptionBackend"
Contract for all encryption backends.
Implementors provide:
backend_id— read-only property returning the unique envelope backend identifier byte.sync_encrypt/sync_decrypt— synchronous methods used by SQLAlchemy TypeDecorators in sync contexts.encrypt/decrypt— async wrappers for use in async application code.
The session service uses this protocol for runtime validation at initialization and static type checkers verify conformance at analysis time.
This is a typing.Protocol — not an abstract base class. Conforming classes do not need to inherit from or import this protocol.
Known limitations of @runtime_checkable:
isinstance()checks verify method existence only. It does not validate parameter types, return types, or whether methods are coroutines. Use a static type checker (mypy, pyright) for full signature validation.
Examples:
Define a minimal conforming backend:
from adk_secure_sessions.protocols import EncryptionBackend
class MyBackend:
@property
def backend_id(self) -> int:
return 0x10
def sync_encrypt(self, plaintext: bytes) -> bytes:
return plaintext # replace with real encryption
def sync_decrypt(self, ciphertext: bytes) -> bytes:
return ciphertext # replace with real decryption
async def encrypt(self, plaintext: bytes) -> bytes:
return self.sync_encrypt(plaintext)
async def decrypt(self, ciphertext: bytes) -> bytes:
return self.sync_decrypt(ciphertext)
assert isinstance(MyBackend(), EncryptionBackend)
Source code in src/adk_secure_sessions/protocols.py
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 | |
backend_id property ¶
sync_encrypt ¶
Encrypt plaintext bytes synchronously.
Used by SQLAlchemy TypeDecorators that operate in sync contexts. The async encrypt method should delegate to this via asyncio.to_thread().
| PARAMETER | DESCRIPTION |
|---|---|
plaintext | Raw bytes to encrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted ciphertext as bytes. |
Examples:
Source code in src/adk_secure_sessions/protocols.py
sync_decrypt ¶
Decrypt ciphertext bytes synchronously.
Used by SQLAlchemy TypeDecorators that operate in sync contexts. The async decrypt method should delegate to this via asyncio.to_thread().
| PARAMETER | DESCRIPTION |
|---|---|
ciphertext | Encrypted bytes to decrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Decrypted plaintext as bytes. |
Examples:
Source code in src/adk_secure_sessions/protocols.py
encrypt async ¶
Encrypt plaintext bytes asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
plaintext | Raw bytes to encrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted ciphertext as bytes. |
Examples:
Source code in src/adk_secure_sessions/protocols.py
decrypt async ¶
Decrypt ciphertext bytes asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
ciphertext | Encrypted bytes to decrypt. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Decrypted plaintext as bytes. |
Examples:
Source code in src/adk_secure_sessions/protocols.py
EncryptedSessionService ¶
Bases: DatabaseSessionService
flowchart TD
adk_secure_sessions.EncryptedSessionService[EncryptedSessionService]
click adk_secure_sessions.EncryptedSessionService href "" "adk_secure_sessions.EncryptedSessionService"
Encrypted session service wrapping DatabaseSessionService.
Subclasses ADK's DatabaseSessionService to inject encrypted SQLAlchemy models via _get_schema_classes() and _prepare_tables(). All CRUD methods (create_session, get_session, list_sessions, delete_session, append_event) are inherited without modification.
Supports multiple encryption backends for incremental migration. The backend parameter is the primary backend used for new writes. The additional_backends parameter provides legacy decrypt capability. Backends are fixed after construction — they cannot be added or removed post-init.
| ATTRIBUTE | DESCRIPTION |
|---|---|
db_engine | The SQLAlchemy async engine (inherited). TYPE: |
Examples:
Create a service with SQLite:
from adk_secure_sessions import FernetBackend, EncryptedSessionService
backend = FernetBackend("my-secret-passphrase")
service = EncryptedSessionService(
db_url="sqlite+aiosqlite:///sessions.db",
backend=backend,
)
session = await service.create_session(
app_name="my-agent",
user_id="user-123",
state={"secret": "sensitive-data"},
)
Multi-backend migration (new writes use AES-GCM, legacy Fernet sessions remain readable):
from adk_secure_sessions import (
AesGcmBackend,
FernetBackend,
EncryptedSessionService,
)
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
fernet = FernetBackend("old-passphrase")
aes_gcm = AesGcmBackend(key=AESGCM.generate_key(bit_length=256))
service = EncryptedSessionService(
db_url="sqlite+aiosqlite:///sessions.db",
backend=aes_gcm,
additional_backends=[fernet],
)
Source code in src/adk_secure_sessions/services/encrypted_session.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 | |
__init__ ¶
__init__(
db_url: str,
backend: EncryptionBackend,
additional_backends: Sequence[EncryptionBackend] = (),
**kwargs: Any,
) -> None
Initialize the encrypted session service.
Uses backend.sync_encrypt, backend.sync_decrypt, and backend.backend_id from the protocol to configure the EncryptedJSON TypeDecorator. When additional_backends are provided, their decrypt functions are included in the dispatch map for reading legacy-encrypted data.
Backends are fixed after construction. The cache_ok = True on EncryptedJSON means SQLAlchemy may cache the type instance — post-init mutation would be a correctness bug.
| PARAMETER | DESCRIPTION |
|---|---|
db_url | SQLAlchemy connection string (e.g., TYPE: |
backend | Primary encryption backend. Used for all new writes and included in the decrypt dispatch map. TYPE: |
additional_backends | Extra backends for decrypt-only dispatch. Each must conform to TYPE: |
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs | Additional keyword arguments passed to TYPE: |
| RAISES | DESCRIPTION |
|---|---|
ConfigurationError | If backend or any entry in additional_backends does not conform to |
Source code in src/adk_secure_sessions/services/encrypted_session.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 | |
decrypt_json async ¶
decrypt_json(
envelope: bytes, backend: EncryptionBackend
) -> str
Decrypt an encrypted envelope back to a JSON string.
| PARAMETER | DESCRIPTION |
|---|---|
envelope | Encrypted envelope bytes (>= 3 bytes). TYPE: |
backend | Any TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
str | Original JSON string. |
| RAISES | DESCRIPTION |
|---|---|
DecryptionError | If envelope is invalid, tampered, backend fails, or decrypted bytes are not valid UTF-8. |
Examples:
Source code in src/adk_secure_sessions/serialization.py
decrypt_session async ¶
decrypt_session(
envelope: bytes, backend: EncryptionBackend
) -> dict[str, Any]
Decrypt an encrypted envelope back to a session state dict.
| PARAMETER | DESCRIPTION |
|---|---|
envelope | Encrypted envelope bytes (>= 3 bytes). TYPE: |
backend | Any TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] | Original Python dictionary. |
| RAISES | DESCRIPTION |
|---|---|
DecryptionError | If envelope is invalid, tampered, or backend fails. |
SerializationError | If decrypted bytes are not valid JSON. |
Examples:
Source code in src/adk_secure_sessions/serialization.py
encrypt_json async ¶
encrypt_json(
json_str: str,
backend: EncryptionBackend,
backend_id: int,
) -> bytes
Encrypt a pre-serialized JSON string into an encrypted envelope.
| PARAMETER | DESCRIPTION |
|---|---|
json_str | Valid JSON string (e.g., from TYPE: |
backend | Any TYPE: |
backend_id | Integer identifying the backend. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted envelope bytes: |
Examples:
Source code in src/adk_secure_sessions/serialization.py
encrypt_session async ¶
encrypt_session(
data: dict[str, Any],
backend: EncryptionBackend,
backend_id: int,
) -> bytes
Serialize a session state dict to an encrypted envelope.
| PARAMETER | DESCRIPTION |
|---|---|
data | JSON-serializable Python dictionary. TYPE: |
backend | Any TYPE: |
backend_id | Integer identifying the backend. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bytes | Encrypted envelope bytes: |
| RAISES | DESCRIPTION |
|---|---|
SerializationError | If data cannot be serialized to JSON. |
Examples: