rtty-soda 0.1.3__tar.gz → 0.1.5__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.

Potentially problematic release.


This version of rtty-soda might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rtty-soda
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: A CLI tool for Unix-like environments to encrypt a RTTY session using NaCl
5
5
  Keywords: cli,encryption,libsodium,nacl,rtty
6
6
  Author: Theo Saveliev
@@ -54,8 +54,8 @@ A CLI tool for Unix-like environments to encrypt a RTTY session using NaCl.
54
54
  #### Docker
55
55
 
56
56
  ```
57
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.3
58
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.3-tools
57
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.5
58
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.5-tools
59
59
  ```
60
60
 
61
61
 
@@ -29,8 +29,8 @@ A CLI tool for Unix-like environments to encrypt a RTTY session using NaCl.
29
29
  #### Docker
30
30
 
31
31
  ```
32
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.3
33
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.3-tools
32
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.5
33
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.1.5-tools
34
34
  ```
35
35
 
36
36
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rtty-soda"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "A CLI tool for Unix-like environments to encrypt a RTTY session using NaCl"
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -95,8 +95,8 @@ docker = ["docker-build", "docker-push"]
95
95
  shell = """
96
96
  IMAGE_TAG=nett/rtty-soda:$(uv version --short)
97
97
  PLATFORM=linux/amd64,linux/arm64/v8
98
- docker build --tag ${IMAGE_TAG} --platform ${PLATFORM} --file Dockerfile .
99
- docker build --tag ${IMAGE_TAG}-tools --platform ${PLATFORM} --file Dockerfile-tools .
98
+ docker build --tag ${IMAGE_TAG} --platform ${PLATFORM} --file Dockerfile --no-cache .
99
+ docker build --tag ${IMAGE_TAG}-tools --platform ${PLATFORM} --file Dockerfile-tools --no-cache .
100
100
  """
101
101
 
102
102
  [tool.poe.tasks.docker-push]
@@ -1,4 +1,6 @@
1
+ import random
1
2
  import re
3
+ import string
2
4
  from pathlib import Path
3
5
  from typing import TextIO, cast
4
6
 
@@ -14,6 +16,7 @@ __all__ = [
14
16
  "read_plaintext_bytes",
15
17
  "read_str",
16
18
  "remove_whitespace",
19
+ "write_bytes_atomic",
17
20
  "write_output",
18
21
  ]
19
22
 
@@ -51,6 +54,13 @@ def read_ciphertext_bytes(source: Path, in_enc: Encoder) -> bytes:
51
54
  return read_clean_bytes(source)
52
55
 
53
56
 
57
+ def write_bytes_atomic(target: Path, data: bytes) -> None:
58
+ temp_name = "".join(random.choices(string.ascii_lowercase, k=10)) # noqa: S311
59
+ temp_path = target.parent / temp_name
60
+ temp_path.write_bytes(data)
61
+ temp_path.replace(target)
62
+
63
+
54
64
  def write_output(target: Path | None, data: bytes, out_enc: Encoder) -> None:
55
65
  if target is None or target.stem == "-":
56
66
  if out_enc == RawEncoder:
@@ -67,7 +77,7 @@ def write_output(target: Path | None, data: bytes, out_enc: Encoder) -> None:
67
77
  f"Overwrite the output file? ({target})", default=False, abort=True
68
78
  )
69
79
 
70
- target.write_bytes(data)
80
+ write_bytes_atomic(target, data)
71
81
 
72
82
 
73
83
  def print_stats(plaintext: bytes, ciphertext: bytes) -> None:
@@ -10,6 +10,9 @@ def decode_bytes(data: bytes) -> str:
10
10
 
11
11
 
12
12
  def int_to_base(number: int, alphabet: str) -> str:
13
+ if number == 0:
14
+ return alphabet[0]
15
+
13
16
  result: list[str] = []
14
17
  base = len(alphabet)
15
18
  abs_number = abs(number)
@@ -35,6 +38,9 @@ def bytes_to_base(source: bytes, alphabet: str) -> str:
35
38
 
36
39
 
37
40
  def int_to_bytes(number: int) -> bytes:
41
+ if number == 0:
42
+ return b"\x00"
43
+
38
44
  buffer = bytearray()
39
45
  while number:
40
46
  buffer.append(number & 0xFF)