artemis_framework 0.1.2__tar.gz → 0.1.3__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.
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/PKG-INFO +1 -1
- artemis_framework-0.1.3/artemis_framework/asphodel/core/encrypt_decrypt.py +160 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/pyproject.toml +1 -1
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/LICENSE +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/README.md +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/__init__.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/__main__.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/asphodel/__init__.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/asphodel/core/__init__.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/asphodel/core/gpg_context.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/asphodel/core/key_management.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/elysium/__ini +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/elysium/__init__.py +0 -0
- {artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/tartarus/__init__.py +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from artemis_framework.asphodel.core.gpg_context import build_gpg, check_result
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def encrypt_to_recipients(
|
|
10
|
+
gpg: "gnupg.GPG", # type: ignore
|
|
11
|
+
plaintext: str | bytes,
|
|
12
|
+
recipients: list[str],
|
|
13
|
+
*,
|
|
14
|
+
armor: bool = True,
|
|
15
|
+
sign: str | None = None,
|
|
16
|
+
passphrase: str | None = None,
|
|
17
|
+
always_trust: bool = True,
|
|
18
|
+
extra_args: list[str] | None = None
|
|
19
|
+
) -> str | bytes | None:
|
|
20
|
+
result = gpg.encrypt(
|
|
21
|
+
plaintext,
|
|
22
|
+
recipients,
|
|
23
|
+
armor=armor,
|
|
24
|
+
sign=sign,
|
|
25
|
+
passphrase=passphrase,
|
|
26
|
+
always_trust=always_trust,
|
|
27
|
+
extra_args=extra_args or []
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if not check_result(result, label=f"encrypt_to_recipients({recipients})"):
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
return result.data.decode("ascii") if armor else result.data
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def encrypt_symmetric(
|
|
37
|
+
gpg: "gnupg.GPG", # type: ignore
|
|
38
|
+
plaintext: str | bytes,
|
|
39
|
+
passphrase: str,
|
|
40
|
+
*,
|
|
41
|
+
armor: bool = True,
|
|
42
|
+
cipher_algo: str = "AES256"
|
|
43
|
+
) -> str | bytes | None:
|
|
44
|
+
result = gpg.encrypt(
|
|
45
|
+
plaintext,
|
|
46
|
+
recipients=None,
|
|
47
|
+
symmetric=True,
|
|
48
|
+
passphrase=passphrase,
|
|
49
|
+
armor=armor,
|
|
50
|
+
extra_args=["--cipher-algo", cipher_algo, "--no-symkey-cache"]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if not check_result(result, label="encrypt_symmetric"):
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
return result.data.decode("ascii") if armor else result.data
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def decrypt_data(
|
|
60
|
+
gpg: "gnupg.GPG", # type: ignore
|
|
61
|
+
ciphertext: str | bytes,
|
|
62
|
+
*,
|
|
63
|
+
passphrase: str | None = None,
|
|
64
|
+
always_trust: bool = True
|
|
65
|
+
) -> bytes | None:
|
|
66
|
+
result = gpg.decrypt(
|
|
67
|
+
ciphertext,
|
|
68
|
+
passphrase=passphrase,
|
|
69
|
+
always_trust=always_trust
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if not check_result(result, label="decrypt_data"):
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
return result.data
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def encrypt_file(
|
|
79
|
+
gpg: "gnupg.GPG", # type: ignore
|
|
80
|
+
input_path: Path | str,
|
|
81
|
+
recipients: list[str],
|
|
82
|
+
*,
|
|
83
|
+
output_path: Path | str | None = None,
|
|
84
|
+
armor: bool = True,
|
|
85
|
+
sign : str | None = None,
|
|
86
|
+
passphrase: str | None = None,
|
|
87
|
+
always_trust: bool = True
|
|
88
|
+
) -> Path | None:
|
|
89
|
+
src = Path(input_path)
|
|
90
|
+
if not src.exists():
|
|
91
|
+
print(f"[ERR] encrypt_file: {src} not found.")
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
dst = Path(output_path) if output_path else src.with_suffix(src.suffix + (".asc" if armor else ".gpg"))
|
|
95
|
+
|
|
96
|
+
with open(src, "rb") as file:
|
|
97
|
+
result = gpg.encrypt_file(
|
|
98
|
+
file,
|
|
99
|
+
recipients=recipients,
|
|
100
|
+
armor=armor,
|
|
101
|
+
sign=sign,
|
|
102
|
+
passphrase=passphrase,
|
|
103
|
+
always_trust=always_trust,
|
|
104
|
+
output=str(dst)
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
if not check_result(result, label=f"encrypt_file({src.name})"):
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
print(f" output: {dst}")
|
|
111
|
+
return dst
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def decrypt_file(
|
|
115
|
+
gpg: "gnupg.GPG", # type: ignore
|
|
116
|
+
input_path: Path | str,
|
|
117
|
+
*,
|
|
118
|
+
output_path: Path | str | None = None,
|
|
119
|
+
passphrase: str | None = None,
|
|
120
|
+
always_trust: bool = True
|
|
121
|
+
) -> Path | None:
|
|
122
|
+
src = Path(input_path)
|
|
123
|
+
if not src.exists():
|
|
124
|
+
print(f"[ERR] decrypt_file: {src} not found.")
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
if output_path:
|
|
128
|
+
dst = Path(output_path)
|
|
129
|
+
else:
|
|
130
|
+
dst = src.with_suffix("")
|
|
131
|
+
|
|
132
|
+
with open(src, "rb") as file:
|
|
133
|
+
result = gpg.decrypt_file(
|
|
134
|
+
file,
|
|
135
|
+
passphrase=passphrase,
|
|
136
|
+
always_trust=always_trust,
|
|
137
|
+
output=str(dst)
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
if not check_result(result, label=f"decrypt_file({src.name})"):
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
print(f" output: {dst}")
|
|
144
|
+
return dst
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def print_decrypt_signature_info(result) -> None:
|
|
148
|
+
sig_id = getattr(result, "signature_id", None)
|
|
149
|
+
key_id = getattr(result, "key_id", None)
|
|
150
|
+
uid = getattr(result, "username", None)
|
|
151
|
+
trust = getattr(result, "trust_text", None)
|
|
152
|
+
|
|
153
|
+
if sig_id or key_id:
|
|
154
|
+
print("\n [Signature embedded in ciphertext]")
|
|
155
|
+
print(f" signer UID : {uid or '<unknown>'}")
|
|
156
|
+
print(f" key ID : {key_id or '<unknown>'}")
|
|
157
|
+
print(f" trust : {trust or '<unknown>'}")
|
|
158
|
+
else:
|
|
159
|
+
print("\n [No embedded signature detected]")
|
|
160
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/asphodel/core/__init__.py
RENAMED
|
File without changes
|
{artemis_framework-0.1.2 → artemis_framework-0.1.3}/artemis_framework/asphodel/core/gpg_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|