bytencrypt 0.1.0__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.
- bytencrypt-0.1.0/LICENSE +21 -0
- bytencrypt-0.1.0/PKG-INFO +14 -0
- bytencrypt-0.1.0/README.md +1 -0
- bytencrypt-0.1.0/pyproject.toml +12 -0
- bytencrypt-0.1.0/setup.cfg +4 -0
- bytencrypt-0.1.0/src/bytencrypt.egg-info/PKG-INFO +14 -0
- bytencrypt-0.1.0/src/bytencrypt.egg-info/SOURCES.txt +13 -0
- bytencrypt-0.1.0/src/bytencrypt.egg-info/dependency_links.txt +1 -0
- bytencrypt-0.1.0/src/bytencrypt.egg-info/requires.txt +4 -0
- bytencrypt-0.1.0/src/bytencrypt.egg-info/top_level.txt +4 -0
- bytencrypt-0.1.0/src/downloader.py +29 -0
- bytencrypt-0.1.0/src/encryption.py +59 -0
- bytencrypt-0.1.0/src/torrent.py +51 -0
- bytencrypt-0.1.0/src/vault.py +32 -0
- bytencrypt-0.1.0/tests/test_encrypt_decrypt.py +5 -0
bytencrypt-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Teraflop AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bytencrypt
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: infisicalsdk>=1.0.17
|
|
9
|
+
Requires-Dist: libtorrent>=2.1.1
|
|
10
|
+
Requires-Dist: pynacl>=1.6.2
|
|
11
|
+
Requires-Dist: tqdm>=4.70.0
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
ruff check --select I --fix . && ruff format .
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruff check --select I --fix . && ruff format .
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bytencrypt"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"infisicalsdk>=1.0.17",
|
|
9
|
+
"libtorrent>=2.1.1",
|
|
10
|
+
"pynacl>=1.6.2",
|
|
11
|
+
"tqdm>=4.70.0",
|
|
12
|
+
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bytencrypt
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: infisicalsdk>=1.0.17
|
|
9
|
+
Requires-Dist: libtorrent>=2.1.1
|
|
10
|
+
Requires-Dist: pynacl>=1.6.2
|
|
11
|
+
Requires-Dist: tqdm>=4.70.0
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
ruff check --select I --fix . && ruff format .
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/downloader.py
|
|
5
|
+
src/encryption.py
|
|
6
|
+
src/torrent.py
|
|
7
|
+
src/vault.py
|
|
8
|
+
src/bytencrypt.egg-info/PKG-INFO
|
|
9
|
+
src/bytencrypt.egg-info/SOURCES.txt
|
|
10
|
+
src/bytencrypt.egg-info/dependency_links.txt
|
|
11
|
+
src/bytencrypt.egg-info/requires.txt
|
|
12
|
+
src/bytencrypt.egg-info/top_level.txt
|
|
13
|
+
tests/test_encrypt_decrypt.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import getpass
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
|
|
5
|
+
from encryption import FileCrypt
|
|
6
|
+
from torrent import Torrent
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Downloader:
|
|
10
|
+
def __init__(self, out="downloads", pw=None, stage=None, remove=True, **settings):
|
|
11
|
+
self.out, self.remove = out, remove
|
|
12
|
+
self.stage = stage or os.path.join(
|
|
13
|
+
"/dev/shm" if os.path.isdir("/dev/shm") else tempfile.gettempdir(),
|
|
14
|
+
str(os.getuid()),
|
|
15
|
+
)
|
|
16
|
+
os.makedirs(self.stage, 0o700, exist_ok=True)
|
|
17
|
+
self.fc = FileCrypt(pw or getpass.getpass("password: "))
|
|
18
|
+
self.torrent = Torrent(self.stage, **settings)
|
|
19
|
+
|
|
20
|
+
def get(self, *srcs):
|
|
21
|
+
handles = [self.torrent.add(s) for s in srcs]
|
|
22
|
+
done = []
|
|
23
|
+
for h in handles:
|
|
24
|
+
self.torrent.wait(h)
|
|
25
|
+
for f in self.torrent.files(h):
|
|
26
|
+
dst = os.path.join(self.out, os.path.relpath(f, self.stage)) + ".enc"
|
|
27
|
+
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
|
28
|
+
done.append(self.fc.encrypt(f, out=dst, remove=self.remove))
|
|
29
|
+
return done
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import nacl.pwhash
|
|
4
|
+
import nacl.secret
|
|
5
|
+
import nacl.utils
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FileCrypt:
|
|
9
|
+
CHUNK = 1 << 20
|
|
10
|
+
A = nacl.secret.Aead
|
|
11
|
+
KDF = nacl.pwhash.argon2id
|
|
12
|
+
BLOCK = A.NONCE_SIZE + CHUNK + A.MACBYTES
|
|
13
|
+
|
|
14
|
+
def __init__(self, pw):
|
|
15
|
+
self.pw = pw.encode() if isinstance(pw, str) else pw
|
|
16
|
+
|
|
17
|
+
def _aead(self, salt):
|
|
18
|
+
key = self.KDF.kdf(
|
|
19
|
+
self.A.KEY_SIZE,
|
|
20
|
+
self.pw,
|
|
21
|
+
salt,
|
|
22
|
+
self.KDF.OPSLIMIT_MODERATE,
|
|
23
|
+
self.KDF.MEMLIMIT_MODERATE,
|
|
24
|
+
)
|
|
25
|
+
return self.A(key)
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _aad(i, last):
|
|
29
|
+
return i.to_bytes(8, "big") + bytes([last])
|
|
30
|
+
|
|
31
|
+
def encrypt(self, path, out=None, remove=True):
|
|
32
|
+
out = out or path + ".enc"
|
|
33
|
+
salt = nacl.utils.random(self.KDF.SALTBYTES)
|
|
34
|
+
aead = self._aead(salt)
|
|
35
|
+
with open(path, "rb") as f, open(out, "wb") as o:
|
|
36
|
+
o.write(salt)
|
|
37
|
+
i, last = 0, False
|
|
38
|
+
while not last:
|
|
39
|
+
chunk = f.read(self.CHUNK)
|
|
40
|
+
last = len(chunk) < self.CHUNK
|
|
41
|
+
o.write(aead.encrypt(chunk, aad=self._aad(i, last)))
|
|
42
|
+
i += 1
|
|
43
|
+
if remove:
|
|
44
|
+
os.remove(path)
|
|
45
|
+
return out
|
|
46
|
+
|
|
47
|
+
def decrypt(self, path, out=None, remove=True):
|
|
48
|
+
out = out or path.removesuffix(".enc")
|
|
49
|
+
with open(path, "rb") as f, open(out, "wb") as o:
|
|
50
|
+
aead = self._aead(f.read(self.KDF.SALTBYTES))
|
|
51
|
+
i, last = 0, False
|
|
52
|
+
while not last:
|
|
53
|
+
block = f.read(self.BLOCK)
|
|
54
|
+
last = len(block) < self.BLOCK
|
|
55
|
+
o.write(aead.decrypt(block, aad=self._aad(i, last)))
|
|
56
|
+
i += 1
|
|
57
|
+
if remove:
|
|
58
|
+
os.remove(path)
|
|
59
|
+
return out
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
import libtorrent as lt
|
|
5
|
+
from tqdm import tqdm
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Torrent:
|
|
9
|
+
SETTINGS = {
|
|
10
|
+
"listen_interfaces": "0.0.0.0:6881",
|
|
11
|
+
"out_enc_policy": lt.enc_policy.forced,
|
|
12
|
+
"in_enc_policy": lt.enc_policy.forced,
|
|
13
|
+
"allowed_enc_level": lt.enc_level.rc4,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def __init__(self, save="downloads", **settings):
|
|
17
|
+
self.save = save
|
|
18
|
+
os.makedirs(save, exist_ok=True)
|
|
19
|
+
self.ses = lt.session({**self.SETTINGS, **settings})
|
|
20
|
+
|
|
21
|
+
def add(self, src):
|
|
22
|
+
if src.startswith("magnet:"):
|
|
23
|
+
p = lt.parse_magnet_uri(src)
|
|
24
|
+
else:
|
|
25
|
+
p = lt.add_torrent_params()
|
|
26
|
+
p.ti = lt.torrent_info(src)
|
|
27
|
+
p.save_path = self.save
|
|
28
|
+
return self.ses.add_torrent(p)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def wait(h, interval=1):
|
|
32
|
+
s = h.status()
|
|
33
|
+
with tqdm(total=s.total_wanted, unit="B", unit_scale=True, desc=s.name) as bar:
|
|
34
|
+
while not s.is_seeding:
|
|
35
|
+
time.sleep(interval)
|
|
36
|
+
s = h.status()
|
|
37
|
+
bar.total = s.total_wanted
|
|
38
|
+
bar.update(s.total_wanted_done - bar.n)
|
|
39
|
+
bar.set_postfix(peers=s.num_peers, refresh=False)
|
|
40
|
+
|
|
41
|
+
def files(self, h):
|
|
42
|
+
fs = h.torrent_file().files()
|
|
43
|
+
paths = (
|
|
44
|
+
os.path.join(self.save, fs.file_path(i)) for i in range(fs.num_files())
|
|
45
|
+
)
|
|
46
|
+
return [p for p in paths if os.path.isfile(p)]
|
|
47
|
+
|
|
48
|
+
def download(self, src):
|
|
49
|
+
h = self.add(src)
|
|
50
|
+
self.wait(h)
|
|
51
|
+
return self.files(h)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from infisical_sdk import InfisicalSDKClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Vault:
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
project_id=None,
|
|
10
|
+
env="prod",
|
|
11
|
+
path="/",
|
|
12
|
+
host=None,
|
|
13
|
+
client_id=None,
|
|
14
|
+
client_secret=None,
|
|
15
|
+
):
|
|
16
|
+
self.project_id = project_id or os.environ["INFISICAL_PROJECT_ID"]
|
|
17
|
+
self.env, self.path = env, path
|
|
18
|
+
self.client = InfisicalSDKClient(
|
|
19
|
+
host=host or os.environ.get("INFISICAL_HOST", "https://app.infisical.com")
|
|
20
|
+
)
|
|
21
|
+
self.client.auth.universal_auth.login(
|
|
22
|
+
client_id or os.environ["INFISICAL_CLIENT_ID"],
|
|
23
|
+
client_secret or os.environ["INFISICAL_CLIENT_SECRET"],
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def get(self, name):
|
|
27
|
+
return self.client.secrets.get_secret_by_name(
|
|
28
|
+
secret_name=name,
|
|
29
|
+
project_id=self.project_id,
|
|
30
|
+
environment_slug=self.env,
|
|
31
|
+
secret_path=self.path,
|
|
32
|
+
).secretValue
|