pydantic_encryption 0.9.0__tar.gz → 0.9.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/PKG-INFO +2 -2
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/README.md +1 -1
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/bulk.py +25 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/descriptor.py +2 -6
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pyproject.toml +1 -1
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/LICENSE +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/base.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/blind_index/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/blind_index/argon2.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/blind_index/hmac_sha256.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/encryption/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/encryption/aws.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/encryption/fernet.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/hashing/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/hashing/argon2.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/registry.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/config.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/async_bridge.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/blind_index.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/deferred.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/encryption.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/hashing.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/serialization.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/sqlalchemy/state.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/lazy.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/models/__init__.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/models/base.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/normalization.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/types.py +0 -0
- {pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/scripts/run_tests.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pydantic_encryption
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
4
4
|
Summary: Encryption, hashing, and blind indexing for Pydantic
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: Julien Kmec
|
|
@@ -222,7 +222,7 @@ async with AsyncSession(engine) as session:
|
|
|
222
222
|
|
|
223
223
|
### Safety: catching accidental ciphertext access
|
|
224
224
|
|
|
225
|
-
Reads go through the on-access descriptor. If a `DeferredDecryptMixin` column is still encrypted when accessed
|
|
225
|
+
Reads go through the on-access descriptor. If a `DeferredDecryptMixin` column is still encrypted when accessed on a **detached** instance (no session), the descriptor raises `EncryptedValueAccessError`; call `await instance.decrypt()` or `await decrypt_pending_fields(session)` first. Reads from plain async code (outside an SA greenlet) fall back to a synchronous batch decrypt across the session's pending siblings and return plaintext transparently.
|
|
226
226
|
|
|
227
227
|
If anything bypasses the descriptor and hands you an `EncryptedValue` directly (raw `state.dict[col]`, a logged row), coercing it via `str(value)` / `f"{value}"` / `"%s" % value` raises the same error. `repr(value)` is a safe `<EncryptedValue: N bytes>` marker, and `bytes(value)` returns the raw ciphertext. Use `is_encrypted(value)` to guard at a boundary.
|
|
228
228
|
|
|
@@ -179,7 +179,7 @@ async with AsyncSession(engine) as session:
|
|
|
179
179
|
|
|
180
180
|
### Safety: catching accidental ciphertext access
|
|
181
181
|
|
|
182
|
-
Reads go through the on-access descriptor. If a `DeferredDecryptMixin` column is still encrypted when accessed
|
|
182
|
+
Reads go through the on-access descriptor. If a `DeferredDecryptMixin` column is still encrypted when accessed on a **detached** instance (no session), the descriptor raises `EncryptedValueAccessError`; call `await instance.decrypt()` or `await decrypt_pending_fields(session)` first. Reads from plain async code (outside an SA greenlet) fall back to a synchronous batch decrypt across the session's pending siblings and return plaintext transparently.
|
|
183
183
|
|
|
184
184
|
If anything bypasses the descriptor and hands you an `EncryptedValue` directly (raw `state.dict[col]`, a logged row), coercing it via `str(value)` / `f"{value}"` / `"%s" % value` raises the same error. `repr(value)` is a safe `<EncryptedValue: N bytes>` marker, and `bytes(value)` returns the raw ciphertext. Use `is_encrypted(value)` to guard at a boundary.
|
|
185
185
|
|
|
@@ -109,6 +109,30 @@ async def decrypt_rows(
|
|
|
109
109
|
set_decrypted(row, key, plaintext)
|
|
110
110
|
|
|
111
111
|
|
|
112
|
+
def decrypt_rows_sync(
|
|
113
|
+
rows: Iterable[Any], *columns: InstrumentedAttribute | str
|
|
114
|
+
) -> None:
|
|
115
|
+
"""Sync decrypt fallback for descriptor reads outside an async-session greenlet."""
|
|
116
|
+
|
|
117
|
+
if not columns:
|
|
118
|
+
return
|
|
119
|
+
|
|
120
|
+
rows_list = list(rows)
|
|
121
|
+
if not rows_list:
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
backend = _resolve_backend()
|
|
125
|
+
column_keys = [_column_key(c) for c in columns]
|
|
126
|
+
|
|
127
|
+
for row in rows_list:
|
|
128
|
+
for key in column_keys:
|
|
129
|
+
value = read_raw_cell(row, key)
|
|
130
|
+
if not isinstance(value, EncryptedValue):
|
|
131
|
+
continue
|
|
132
|
+
plaintext = decode_value(backend.decrypt(bytes(value)))
|
|
133
|
+
set_decrypted(row, key, plaintext)
|
|
134
|
+
|
|
135
|
+
|
|
112
136
|
async def decrypt_values(
|
|
113
137
|
values: Iterable[Any],
|
|
114
138
|
*,
|
|
@@ -227,5 +251,6 @@ __all__ = [
|
|
|
227
251
|
"collect_encrypted_cells",
|
|
228
252
|
"decrypt_pending_fields",
|
|
229
253
|
"decrypt_rows",
|
|
254
|
+
"decrypt_rows_sync",
|
|
230
255
|
"decrypt_values",
|
|
231
256
|
]
|
|
@@ -13,7 +13,7 @@ from sqlalchemy.exc import MissingGreenlet
|
|
|
13
13
|
from sqlalchemy.orm import object_session
|
|
14
14
|
|
|
15
15
|
from pydantic_encryption.integrations.sqlalchemy.state import pending_siblings
|
|
16
|
-
from pydantic_encryption.integrations.sqlalchemy.bulk import decrypt_rows
|
|
16
|
+
from pydantic_encryption.integrations.sqlalchemy.bulk import decrypt_rows, decrypt_rows_sync
|
|
17
17
|
from pydantic_encryption.types import EncryptedValue, EncryptedValueAccessError
|
|
18
18
|
|
|
19
19
|
|
|
@@ -52,11 +52,7 @@ class DecryptOnAccessDescriptor:
|
|
|
52
52
|
try:
|
|
53
53
|
await_(decrypt_rows(rows, self._column_key))
|
|
54
54
|
except MissingGreenlet:
|
|
55
|
-
|
|
56
|
-
f"Cannot decrypt {self._cls.__name__}.{self._column_key} outside of an "
|
|
57
|
-
"async-session greenlet. Call `await decrypt_pending_fields(session)` or "
|
|
58
|
-
"`await instance.decrypt()` first."
|
|
59
|
-
)
|
|
55
|
+
decrypt_rows_sync(rows, self._column_key)
|
|
60
56
|
|
|
61
57
|
return self._wrapped.__get__(instance, owner)
|
|
62
58
|
|
|
File without changes
|
|
File without changes
|
{pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/__init__.py
RENAMED
|
File without changes
|
{pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/adapters/registry.py
RENAMED
|
File without changes
|
|
File without changes
|
{pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/integrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/models/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{pydantic_encryption-0.9.0 → pydantic_encryption-0.9.2}/pydantic_encryption/normalization.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|