Skip to content

Commit

Permalink
Add compression
Browse files Browse the repository at this point in the history
  • Loading branch information
zwimer committed Jan 12, 2024
1 parent ea6c848 commit dc657a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rpipe/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "2.2.1"
__version__: str = "2.3.0"
7 changes: 5 additions & 2 deletions rpipe/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import argparse
import hashlib
import zlib
import sys
import os

Expand All @@ -18,6 +19,7 @@
config_file = Path.home() / ".config" / "pipe.json"
_timeout: int = 60
_PASSWORD_ENV: str = "RPIPE_PASSWORD"
_ZLIB_LEVEL: int = 6


@dataclass
Expand All @@ -39,10 +41,11 @@ def _crypt(encrypt: bool, data: bytes, password: str | None) -> bytes:
if encrypt:
salt = get_random_bytes(AES.block_size)
conf = AES.new(hashlib.scrypt(salt=salt, **opts), mode) # type: ignore
text, tag = conf.encrypt_and_digest(data)
text, tag = conf.encrypt_and_digest(zlib.compress(data, level=_ZLIB_LEVEL))
return b".".join(b64encode(i) for i in (text, salt, conf.nonce, tag))
text, salt, nonce, tag = (b64decode(i) for i in data.split(b"."))
return AES.new(hashlib.scrypt(salt=salt, **opts), mode, nonce=nonce).decrypt_and_verify(text, tag) # type: ignore
aes = AES.new(hashlib.scrypt(salt=salt, **opts), mode, nonce=nonce) # type: ignore
return zlib.decompress(aes.decrypt_and_verify(text, tag))


#
Expand Down

0 comments on commit dc657a1

Please sign in to comment.