rtty-soda 0.2.0__tar.gz → 0.2.1__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.

Files changed (22) hide show
  1. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/PKG-INFO +3 -4
  2. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/README.md +2 -3
  3. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/pyproject.toml +1 -1
  4. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/cli_io.py +16 -19
  5. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/base26_encoder.py +4 -2
  6. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/base31_encoder.py +5 -2
  7. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/base36_encoder.py +4 -2
  8. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/base64_encoder.py +4 -3
  9. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/base94_encoder.py +5 -2
  10. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/encoder.py +2 -0
  11. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/raw_encoder.py +4 -2
  12. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/main.py +43 -116
  13. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/__init__.py +0 -0
  14. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/archivers.py +0 -0
  15. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/cryptography/__init__.py +0 -0
  16. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/cryptography/kdf.py +0 -0
  17. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/cryptography/public.py +0 -0
  18. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/cryptography/secret.py +0 -0
  19. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/__init__.py +0 -0
  20. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/encoders/functions.py +0 -0
  21. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/main.pyi +0 -0
  22. {rtty_soda-0.2.0 → rtty_soda-0.2.1}/src/rtty_soda/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rtty-soda
3
- Version: 0.2.0
3
+ Version: 0.2.1
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
@@ -57,8 +57,8 @@ A CLI tool for Unix-like environments to encrypt a RTTY session using NaCl.
57
57
  #### Docker
58
58
 
59
59
  ```
60
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.0
61
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.0-tools
60
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.1
61
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.1-tools
62
62
  ```
63
63
 
64
64
 
@@ -180,7 +180,6 @@ Options:
180
180
  -e, --data-encoding TEXT [default: base64]
181
181
  -c, --compression TEXT [default: zstd]
182
182
  -o, --output-file FILE Write output to file.
183
- --padding INTEGER [default: 0]
184
183
  -v, --verbose Show verbose output.
185
184
  -h, --help Show this message and exit.
186
185
  ```
@@ -34,8 +34,8 @@ A CLI tool for Unix-like environments to encrypt a RTTY session using NaCl.
34
34
  #### Docker
35
35
 
36
36
  ```
37
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.0
38
- % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.0-tools
37
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.1
38
+ % docker run -it --rm -h rtty-soda -v .:/app/host nett/rtty-soda:0.2.1-tools
39
39
  ```
40
40
 
41
41
 
@@ -157,7 +157,6 @@ Options:
157
157
  -e, --data-encoding TEXT [default: base64]
158
158
  -c, --compression TEXT [default: zstd]
159
159
  -o, --output-file FILE Write output to file.
160
- --padding INTEGER [default: 0]
161
160
  -v, --verbose Show verbose output.
162
161
  -h, --help Show this message and exit.
163
162
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rtty-soda"
3
- version = "0.2.0"
3
+ version = "0.2.1"
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" }
@@ -11,6 +11,7 @@ import click
11
11
  from rtty_soda.encoders import Encoder, decode_bytes, encode_str
12
12
 
13
13
  __all__ = [
14
+ "format_output",
14
15
  "pad_newlines",
15
16
  "print_stats",
16
17
  "read_bytes",
@@ -40,15 +41,15 @@ def read_encoded_stripped(source: Path) -> bytes:
40
41
  return encode_str(data)
41
42
 
42
43
 
43
- def read_bytes(source: Path, is_binary: bool) -> bytes:
44
- if is_binary:
44
+ def read_bytes(source: Path, encoder: Encoder) -> bytes:
45
+ if encoder.is_binary:
45
46
  return source.read_bytes()
46
47
 
47
48
  return read_encoded_stripped(source)
48
49
 
49
50
 
50
- def read_key_bytes(source: Path, is_binary: bool, encoder: Encoder) -> bytes:
51
- key = read_bytes(source, is_binary)
51
+ def read_key_bytes(source: Path, encoder: Encoder) -> bytes:
52
+ key = read_bytes(source, encoder)
52
53
  return encoder.decode(key)
53
54
 
54
55
 
@@ -84,27 +85,23 @@ def split_groups(data: str, group_len: int, line_len: int) -> str:
84
85
  return "\n".join(result)
85
86
 
86
87
 
87
- def pad_newlines(data: bytes, count: int) -> bytes:
88
- padding = b"\n" * count
89
- return padding + data + padding
88
+ def pad_newlines(data: str, count: int) -> str:
89
+ padding = "\n" * count
90
+ return padding + data.strip() + "\n" + padding
90
91
 
91
92
 
92
- def write_output(
93
- target: Path | None,
94
- data: bytes,
95
- is_binary: bool,
96
- group_len: int,
97
- line_len: int,
98
- padding: int,
99
- ) -> None:
100
- if not is_binary and (group_len > 0 or line_len > 0):
101
- text = decode_bytes(data)
93
+ def format_output(data: bytes, group_len: int, line_len: int, padding: int) -> bytes:
94
+ text = decode_bytes(data)
95
+ if group_len > 0 or line_len > 0:
102
96
  text = split_groups(text, group_len, line_len)
103
- data = encode_str(text)
104
97
 
105
98
  if padding > 0:
106
- data = pad_newlines(data, padding)
99
+ text = pad_newlines(text, padding)
107
100
 
101
+ return encode_str(text)
102
+
103
+
104
+ def write_output(target: Path | None, data: bytes) -> None:
108
105
  if target is None or target.stem == "-":
109
106
  add_nl = not data.endswith(b"\n")
110
107
  click.echo(data, nl=add_nl)
@@ -1,6 +1,6 @@
1
1
  import string
2
+ from typing import ClassVar
2
3
 
3
- from .encoder import Encoder
4
4
  from .functions import base_to_bytes, bytes_to_base, decode_bytes, encode_str
5
5
 
6
6
  __all__ = ["ALPHABET", "Base26Encoder"]
@@ -8,7 +8,9 @@ __all__ = ["ALPHABET", "Base26Encoder"]
8
8
  ALPHABET = string.ascii_uppercase
9
9
 
10
10
 
11
- class Base26Encoder(Encoder):
11
+ class Base26Encoder:
12
+ is_binary: ClassVar = False
13
+
12
14
  @staticmethod
13
15
  def encode(data: bytes) -> bytes:
14
16
  return encode_str(bytes_to_base(data, ALPHABET))
@@ -1,4 +1,5 @@
1
- from .encoder import Encoder
1
+ from typing import ClassVar
2
+
2
3
  from .functions import base_to_bytes, bytes_to_base, decode_bytes, encode_str
3
4
 
4
5
  __all__ = ["ALPHABET", "Base31Encoder"]
@@ -6,7 +7,9 @@ __all__ = ["ALPHABET", "Base31Encoder"]
6
7
  ALPHABET = "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЭЮЯ"
7
8
 
8
9
 
9
- class Base31Encoder(Encoder):
10
+ class Base31Encoder:
11
+ is_binary: ClassVar = False
12
+
10
13
  @staticmethod
11
14
  def encode(data: bytes) -> bytes:
12
15
  return encode_str(bytes_to_base(data, ALPHABET))
@@ -1,6 +1,6 @@
1
1
  import string
2
+ from typing import ClassVar
2
3
 
3
- from .encoder import Encoder
4
4
  from .functions import base_to_bytes, bytes_to_base, decode_bytes, encode_str
5
5
 
6
6
  __all__ = ["ALPHABET", "Base36Encoder"]
@@ -8,7 +8,9 @@ __all__ = ["ALPHABET", "Base36Encoder"]
8
8
  ALPHABET = string.digits + string.ascii_uppercase
9
9
 
10
10
 
11
- class Base36Encoder(Encoder):
11
+ class Base36Encoder:
12
+ is_binary: ClassVar = False
13
+
12
14
  @staticmethod
13
15
  def encode(data: bytes) -> bytes:
14
16
  return encode_str(bytes_to_base(data, ALPHABET))
@@ -1,11 +1,12 @@
1
1
  import base64
2
-
3
- from .encoder import Encoder
2
+ from typing import ClassVar
4
3
 
5
4
  __all__ = ["Base64Encoder"]
6
5
 
7
6
 
8
- class Base64Encoder(Encoder):
7
+ class Base64Encoder:
8
+ is_binary: ClassVar = False
9
+
9
10
  @staticmethod
10
11
  def encode(data: bytes) -> bytes:
11
12
  return base64.b64encode(data)
@@ -1,4 +1,5 @@
1
- from .encoder import Encoder
1
+ from typing import ClassVar
2
+
2
3
  from .functions import base_to_bytes, bytes_to_base, decode_bytes, encode_str
3
4
 
4
5
  __all__ = ["ALPHABET", "Base94Encoder"]
@@ -6,7 +7,9 @@ __all__ = ["ALPHABET", "Base94Encoder"]
6
7
  ALPHABET = "".join([chr(i) for i in range(33, 127)])
7
8
 
8
9
 
9
- class Base94Encoder(Encoder):
10
+ class Base94Encoder:
11
+ is_binary: ClassVar = False
12
+
10
13
  @staticmethod
11
14
  def encode(data: bytes) -> bytes:
12
15
  return encode_str(bytes_to_base(data, ALPHABET))
@@ -4,6 +4,8 @@ __all__ = ["Encoder"]
4
4
 
5
5
 
6
6
  class Encoder(Protocol):
7
+ is_binary: bool
8
+
7
9
  @staticmethod
8
10
  def encode(data: bytes) -> bytes: ...
9
11
 
@@ -1,9 +1,11 @@
1
- from .encoder import Encoder
1
+ from typing import ClassVar
2
2
 
3
3
  __all__ = ["RawEncoder"]
4
4
 
5
5
 
6
- class RawEncoder(Encoder):
6
+ class RawEncoder:
7
+ is_binary: ClassVar = True
8
+
7
9
  @staticmethod
8
10
  def encode(data: bytes) -> bytes:
9
11
  return data
@@ -6,6 +6,7 @@ from nacl.public import PrivateKey, PublicKey
6
6
 
7
7
  from rtty_soda.archivers import ARCHIVERS, UNARCHIVERS
8
8
  from rtty_soda.cli_io import (
9
+ format_output,
9
10
  print_stats,
10
11
  read_bytes,
11
12
  read_key_bytes,
@@ -52,19 +53,14 @@ def genkey_cmd(
52
53
  Encoding: base26 | base31 | base36 | base64 | base94 | binary
53
54
  """
54
55
  enc = ENCODERS[encoding]
55
- is_bin = encoding == "binary"
56
56
 
57
57
  key = bytes(PrivateKey.generate())
58
58
  key = enc.encode(key)
59
59
 
60
- write_output(
61
- target=output_file,
62
- data=key,
63
- is_binary=is_bin,
64
- group_len=group_len,
65
- line_len=line_len,
66
- padding=padding,
67
- )
60
+ if not enc.is_binary:
61
+ key = format_output(key, group_len, line_len, padding)
62
+
63
+ write_output(target=output_file, data=key)
68
64
 
69
65
 
70
66
  @cli.command() # pyright: ignore[reportAny]
@@ -87,21 +83,16 @@ def pubkey_cmd(
87
83
  Encoding: base26 | base31 | base36 | base64 | base94 | binary
88
84
  """
89
85
  enc = ENCODERS[encoding]
90
- is_bin = encoding == "binary"
91
86
 
92
- priv = read_key_bytes(source=private_key_file, is_binary=is_bin, encoder=enc)
87
+ priv = read_key_bytes(source=private_key_file, encoder=enc)
93
88
  priv = PrivateKey(private_key=priv)
94
89
  pub = bytes(priv.public_key)
95
90
  pub = enc.encode(pub)
96
91
 
97
- write_output(
98
- target=output_file,
99
- data=pub,
100
- is_binary=is_bin,
101
- group_len=group_len,
102
- line_len=line_len,
103
- padding=padding,
104
- )
92
+ if not enc.is_binary:
93
+ pub = format_output(pub, group_len, line_len, padding)
94
+
95
+ write_output(target=output_file, data=pub)
105
96
 
106
97
 
107
98
  @cli.command() # pyright: ignore[reportAny]
@@ -129,20 +120,15 @@ def kdf_cmd(
129
120
  """
130
121
  enc = ENCODERS[encoding]
131
122
  prof = KDF_PROFILES[profile]
132
- is_bin = encoding == "binary"
133
123
 
134
124
  pw = read_password_bytes(password_file)
135
125
  key = kdf(password=pw, profile=prof)
136
126
  key = enc.encode(key)
137
127
 
138
- write_output(
139
- target=output_file,
140
- data=key,
141
- is_binary=is_bin,
142
- group_len=group_len,
143
- line_len=line_len,
144
- padding=padding,
145
- )
128
+ if not enc.is_binary:
129
+ key = format_output(key, group_len, line_len, padding)
130
+
131
+ write_output(target=output_file, data=key)
146
132
 
147
133
 
148
134
  @cli.command(aliases=["e"]) # pyright: ignore[reportAny]
@@ -179,28 +165,20 @@ def encrypt_public_cmd(
179
165
  key_enc = ENCODERS[key_encoding]
180
166
  data_enc = ENCODERS[data_encoding]
181
167
  archiver = ARCHIVERS[compression]
182
- is_bin_key = key_encoding == "binary"
183
- is_bin_data = data_encoding == "binary"
184
168
 
185
- priv = read_key_bytes(
186
- source=private_key_file, is_binary=is_bin_key, encoder=key_enc
187
- )
169
+ priv = read_key_bytes(source=private_key_file, encoder=key_enc)
188
170
  priv = PrivateKey(private_key=priv)
189
- pub = read_key_bytes(source=public_key_file, is_binary=is_bin_key, encoder=key_enc)
171
+ pub = read_key_bytes(source=public_key_file, encoder=key_enc)
190
172
  pub = PublicKey(public_key=pub)
191
173
  data = stats = message_file.read_bytes()
192
174
  data = archiver(data)
193
175
  data = public.encrypt(private=priv, public=pub, data=data)
194
176
  data = data_enc.encode(data)
195
177
 
196
- write_output(
197
- target=output_file,
198
- data=data,
199
- is_binary=is_bin_data,
200
- group_len=group_len,
201
- line_len=line_len,
202
- padding=padding,
203
- )
178
+ if not data_enc.is_binary:
179
+ data = format_output(data, group_len, line_len, padding)
180
+
181
+ write_output(target=output_file, data=data)
204
182
  if verbose:
205
183
  print_stats(plaintext=stats, ciphertext=data)
206
184
 
@@ -237,23 +215,17 @@ def encrypt_secret_cmd(
237
215
  key_enc = ENCODERS[key_encoding]
238
216
  data_enc = ENCODERS[data_encoding]
239
217
  archiver = ARCHIVERS[compression]
240
- is_bin_key = key_encoding == "binary"
241
- is_bin_data = data_encoding == "binary"
242
218
 
243
- key = read_key_bytes(source=key_file, is_binary=is_bin_key, encoder=key_enc)
219
+ key = read_key_bytes(source=key_file, encoder=key_enc)
244
220
  data = stats = message_file.read_bytes()
245
221
  data = archiver(data)
246
222
  data = secret.encrypt(key=key, data=data)
247
223
  data = data_enc.encode(data)
248
224
 
249
- write_output(
250
- target=output_file,
251
- data=data,
252
- is_binary=is_bin_data,
253
- group_len=group_len,
254
- line_len=line_len,
255
- padding=padding,
256
- )
225
+ if not data_enc.is_binary:
226
+ data = format_output(data, group_len, line_len, padding)
227
+
228
+ write_output(target=output_file, data=data)
257
229
  if verbose:
258
230
  print_stats(plaintext=stats, ciphertext=data)
259
231
 
@@ -292,7 +264,6 @@ def encrypt_password_cmd(
292
264
  prof = KDF_PROFILES[kdf_profile]
293
265
  data_enc = ENCODERS[data_encoding]
294
266
  archiver = ARCHIVERS[compression]
295
- is_bin_data = data_encoding == "binary"
296
267
 
297
268
  pw = read_password_bytes(password_file)
298
269
  key = kdf(password=pw, profile=prof)
@@ -301,14 +272,10 @@ def encrypt_password_cmd(
301
272
  data = secret.encrypt(key=key, data=data)
302
273
  data = data_enc.encode(data)
303
274
 
304
- write_output(
305
- target=output_file,
306
- data=data,
307
- is_binary=is_bin_data,
308
- group_len=group_len,
309
- line_len=line_len,
310
- padding=padding,
311
- )
275
+ if not data_enc.is_binary:
276
+ data = format_output(data, group_len, line_len, padding)
277
+
278
+ write_output(target=output_file, data=data)
312
279
  if verbose:
313
280
  print_stats(plaintext=stats, ciphertext=data)
314
281
 
@@ -321,7 +288,6 @@ def encrypt_password_cmd(
321
288
  @click.option("--data-encoding", "-e", default="base64", show_default=True)
322
289
  @click.option("--compression", "-c", default="zstd", show_default=True)
323
290
  @click.option("--output-file", "-o", type=out_path, help="Write output to file.")
324
- @click.option("--padding", default=0, show_default=True)
325
291
  @click.option("--verbose", "-v", is_flag=True, help="Show verbose output.")
326
292
  def decrypt_public_cmd(
327
293
  private_key_file: Path,
@@ -331,7 +297,6 @@ def decrypt_public_cmd(
331
297
  data_encoding: str,
332
298
  compression: str,
333
299
  output_file: Path | None,
334
- padding: int,
335
300
  verbose: bool,
336
301
  ) -> None:
337
302
  """Decrypt Message (Public).
@@ -343,28 +308,17 @@ def decrypt_public_cmd(
343
308
  key_enc = ENCODERS[key_encoding]
344
309
  data_enc = ENCODERS[data_encoding]
345
310
  unarchiver = UNARCHIVERS[compression]
346
- is_bin_key = key_encoding == "binary"
347
- is_bin_data = data_encoding == "binary"
348
311
 
349
- priv = read_key_bytes(
350
- source=private_key_file, is_binary=is_bin_key, encoder=key_enc
351
- )
312
+ priv = read_key_bytes(source=private_key_file, encoder=key_enc)
352
313
  priv = PrivateKey(private_key=priv)
353
- pub = read_key_bytes(source=public_key_file, is_binary=is_bin_key, encoder=key_enc)
314
+ pub = read_key_bytes(source=public_key_file, encoder=key_enc)
354
315
  pub = PublicKey(public_key=pub)
355
- data = stats = read_bytes(source=message_file, is_binary=is_bin_data)
316
+ data = stats = read_bytes(source=message_file, encoder=data_enc)
356
317
  data = data_enc.decode(data)
357
318
  data = public.decrypt(private=priv, public=pub, data=data)
358
319
  data = unarchiver(data)
359
320
 
360
- write_output(
361
- target=output_file,
362
- data=data,
363
- is_binary=True,
364
- group_len=0,
365
- line_len=0,
366
- padding=padding,
367
- )
321
+ write_output(target=output_file, data=data)
368
322
  if verbose:
369
323
  print_stats(plaintext=data, ciphertext=stats)
370
324
 
@@ -376,7 +330,6 @@ def decrypt_public_cmd(
376
330
  @click.option("--data-encoding", "-e", default="base64", show_default=True)
377
331
  @click.option("--compression", "-c", default="zstd", show_default=True)
378
332
  @click.option("--output-file", "-o", type=out_path, help="Write output to file.")
379
- @click.option("--padding", default=0, show_default=True)
380
333
  @click.option("--verbose", "-v", is_flag=True, help="Show verbose output.")
381
334
  def decrypt_secret_cmd(
382
335
  key_file: Path,
@@ -385,7 +338,6 @@ def decrypt_secret_cmd(
385
338
  data_encoding: str,
386
339
  compression: str,
387
340
  output_file: Path | None,
388
- padding: int,
389
341
  verbose: bool,
390
342
  ) -> None:
391
343
  """Decrypt Message (Secret).
@@ -397,23 +349,14 @@ def decrypt_secret_cmd(
397
349
  key_enc = ENCODERS[key_encoding]
398
350
  data_enc = ENCODERS[data_encoding]
399
351
  unarchiver = UNARCHIVERS[compression]
400
- is_bin_key = key_encoding == "binary"
401
- is_bin_data = data_encoding == "binary"
402
352
 
403
- key = read_key_bytes(source=key_file, is_binary=is_bin_key, encoder=key_enc)
404
- data = stats = read_bytes(source=message_file, is_binary=is_bin_data)
353
+ key = read_key_bytes(source=key_file, encoder=key_enc)
354
+ data = stats = read_bytes(source=message_file, encoder=data_enc)
405
355
  data = data_enc.decode(data)
406
356
  data = secret.decrypt(key=key, data=data)
407
357
  data = unarchiver(data)
408
358
 
409
- write_output(
410
- target=output_file,
411
- data=data,
412
- is_binary=True,
413
- group_len=0,
414
- line_len=0,
415
- padding=padding,
416
- )
359
+ write_output(target=output_file, data=data)
417
360
  if verbose:
418
361
  print_stats(plaintext=data, ciphertext=stats)
419
362
 
@@ -425,7 +368,6 @@ def decrypt_secret_cmd(
425
368
  @click.option("--data-encoding", "-e", default="base64", show_default=True)
426
369
  @click.option("--compression", "-c", default="zstd", show_default=True)
427
370
  @click.option("--output-file", "-o", type=out_path, help="Write output to file.")
428
- @click.option("--padding", default=0, show_default=True)
429
371
  @click.option("--verbose", "-v", is_flag=True, help="Show verbose output.")
430
372
  def decrypt_password_cmd(
431
373
  password_file: Path,
@@ -434,7 +376,6 @@ def decrypt_password_cmd(
434
376
  data_encoding: str,
435
377
  compression: str,
436
378
  output_file: Path | None,
437
- padding: int,
438
379
  verbose: bool,
439
380
  ) -> None:
440
381
  """Decrypt Message (Password).
@@ -448,23 +389,15 @@ def decrypt_password_cmd(
448
389
  prof = KDF_PROFILES[kdf_profile]
449
390
  data_enc = ENCODERS[data_encoding]
450
391
  unarchiver = UNARCHIVERS[compression]
451
- is_bin_data = data_encoding == "binary"
452
392
 
453
393
  pw = read_password_bytes(password_file)
454
394
  key = kdf(password=pw, profile=prof)
455
- data = stats = read_bytes(source=message_file, is_binary=is_bin_data)
395
+ data = stats = read_bytes(source=message_file, encoder=data_enc)
456
396
  data = data_enc.decode(data)
457
397
  data = secret.decrypt(key=key, data=data)
458
398
  data = unarchiver(data)
459
399
 
460
- write_output(
461
- target=output_file,
462
- data=data,
463
- is_binary=True,
464
- group_len=0,
465
- line_len=0,
466
- padding=padding,
467
- )
400
+ write_output(target=output_file, data=data)
468
401
  if verbose:
469
402
  print_stats(plaintext=data, ciphertext=stats)
470
403
 
@@ -492,21 +425,15 @@ def encode_cmd(
492
425
  """
493
426
  in_enc = ENCODERS[in_encoding]
494
427
  out_enc = ENCODERS[out_encoding]
495
- in_bin = in_encoding == "binary"
496
- out_bin = out_encoding == "binary"
497
428
 
498
- data = read_bytes(source=file, is_binary=in_bin)
429
+ data = read_bytes(source=file, encoder=in_enc)
499
430
  data = in_enc.decode(data)
500
431
  data = out_enc.encode(data)
501
432
 
502
- write_output(
503
- target=output_file,
504
- data=data,
505
- is_binary=out_bin,
506
- group_len=group_len,
507
- line_len=line_len,
508
- padding=padding,
509
- )
433
+ if not out_enc.is_binary:
434
+ data = format_output(data, group_len, line_len, padding)
435
+
436
+ write_output(target=output_file, data=data)
510
437
 
511
438
 
512
439
  if __name__ == "__main__":