Skip to content

Commit 53f26d4

Browse files
committed
feat(crypt): Add cryptography submodule
1 parent 15cb4a1 commit 53f26d4

File tree

5 files changed

+1531
-0
lines changed

5 files changed

+1531
-0
lines changed

tensorizer/_crypt/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Internal cryptographic library for tensorizer.
3+
These functions are only meant to be used by tensorizer itself,
4+
and are not guaranteed to have a stable interface across versions.
5+
"""
6+
7+
__all__ = (
8+
"available",
9+
"ChunkedEncryption",
10+
"CryptographyError",
11+
"crypto_pwhash_SALTBYTES",
12+
"pwhash",
13+
"random_bytes",
14+
)
15+
16+
from ._exceptions import CryptographyError
17+
18+
try:
19+
from ._encryption import (
20+
ChunkedEncryption,
21+
SequentialEncryption,
22+
crypto_pwhash_SALTBYTES,
23+
pwhash,
24+
random_bytes,
25+
)
26+
27+
available: bool = True
28+
29+
30+
except (OSError, AttributeError):
31+
available: bool = False
32+
33+
def __getattr__(name):
34+
if name in __all__:
35+
raise RuntimeError(
36+
"Encryption module was not initialized,"
37+
" make sure a recent version of libsodium is installed"
38+
)
39+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)