Skip to content

Commit

Permalink
πŸ—“ Jul 18, 2023 7:41:18 PM
Browse files Browse the repository at this point in the history
πŸ’š build steps added/updated
✨ lz4_compress/decompress
πŸ§ͺ tests added/updated
  • Loading branch information
securisec committed Jul 18, 2023
1 parent 74bf9d8 commit a757326
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/tests_multi_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version:
- "3.10"
# - "3.9"

steps:
- uses: actions/checkout@v2.3.4
Expand All @@ -22,13 +21,29 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
# - uses: actions/cache@v1
# id: devcache
# with:
# path: ~/.cache/pip
# key: ${{ runner.os }}-pip-dev-${{ hashFiles('**/requirements.txt') }}
# restore-keys: |
# ${{ runner.os }}-pip-
- uses: actions/cache@v3
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v3
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v3
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install
# if: steps.devcache.outs.cache-hit != 'true'
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ New ideas:
☐ ✨ jwt hmac confusion
☐ ✨ amf encode/decode
☐ ✨ rabbit encryption
☐ ✨ lz4 compression/decompression
☐ ✨ aes cmac
☐ ✨ shuffle
☐ ✨ cetacean encode/decode
Expand Down Expand Up @@ -69,6 +68,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” ✨ lz4 compression/decompression
βœ” πŸš€ improve aes ctr enc/dec to handle iv
βœ” stringify method using json.dumps
βœ” jwt none algo
Expand Down
23 changes: 23 additions & 0 deletions chepy/modules/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import zipfile
import zlib
from typing import TypeVar
import lazy_import

LZ4 = lazy_import.lazy_module("lz4.frame")

from ..core import ChepyCore, ChepyDecorators

Expand Down Expand Up @@ -363,3 +366,23 @@ def raw_deflate(self) -> CompressionT:
"""
self.state = zlib.compress(self._convert_to_bytes())[2:-4]
return self

@ChepyDecorators.call_stack
def lz4_compress(self) -> CompressionT:
"""LZ4 compress
Returns:
Chepy: The Chepy object.
"""
self.state = LZ4.compress(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def lz4_decompress(self) -> CompressionT:
"""LZ4 decompress
Returns:
Chepy: The Chepy object.
"""
self.state = LZ4.decompress(self._convert_to_bytes())
return self
2 changes: 2 additions & 0 deletions chepy/modules/compression.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ class Compression(ChepyCore):
def lzma_decompress(self: CompressionT) -> CompressionT: ...
def raw_inflate(self: CompressionT) -> CompressionT: ...
def raw_deflate(self: CompressionT) -> CompressionT: ...
def lz4_compress(self: CompressionT) -> CompressionT: ...
def lz4_decompress(self: CompressionT) -> CompressionT: ...
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ python-editor
PyYAML
regex
typing_extensions
pretty-errors==1.2.25
pretty-errors==1.2.25
lz4==4.3.2
17 changes: 17 additions & 0 deletions tests/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,20 @@ def test_tar_compress():

def test_raw_deflate_inflate():
assert Chepy("securisec").raw_deflate().raw_inflate().o == b"securisec"


def test_lz4_compress():
assert (
Chepy("data").lz4_compress().to_hex().o
== b"04224d1868400400000000000000cd040000806461746100000000"
)


def test_lz4_decompress():
assert (
Chepy("04224d1868400400000000000000cd040000806461746100000000")
.from_hex()
.lz4_decompress()
.o
== b"data"
)

0 comments on commit a757326

Please sign in to comment.