Skip to content

Commit

Permalink
✅ 🚅 📚 ⚙
Browse files Browse the repository at this point in the history
- lots of lazy loading for speed
- husky pre commit hooks
- updated reqs
- updated plugins with new magic
- docs
- tests updated
- new base 16 methods
  • Loading branch information
securisec committed Apr 14, 2021
1 parent e5b4444 commit dfc3dee
Show file tree
Hide file tree
Showing 19 changed files with 1,079 additions and 76 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/tests_multi_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ jobs:
- name: Install test requirements
run: |
pip install sphinx recommonmark pytest==6.2.1 pytest-cov bandit pyperclip mypy
stubgen -o . -p chepy
pip install sphinx recommonmark pytest==6.2.1 pytest-cov bandit pyperclip
- name: Test with pytest
run: |
Expand Down Expand Up @@ -81,12 +80,12 @@ jobs:
run: |
make -C docs/ clean html
- name: Upload to codecov
if: startsWith(matrix.os,'ubuntu')
uses: codecov/codecov-action@v1.0.3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.xml
# - name: Upload to codecov
# if: startsWith(matrix.os,'ubuntu')
# uses: codecov/codecov-action@v1.0.3
# with:
# token: ${{secrets.CODECOV_TOKEN}}
# file: ./coverage.xml

publish:
runs-on: ubuntu-latest
Expand All @@ -98,9 +97,6 @@ jobs:
uses: actions/setup-python@v2.2.1
with:
python-version: "3.7"
- name: Ensure stubs
run: |
stubgen -o . -p chepy
- name: build
run: |
python setup.py sdist
Expand All @@ -109,4 +105,4 @@ jobs:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
password: ${{ secrets.PYPI_PASSWORD }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.vscode/
.test
ignore/
node_modules/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Plugins:
Methods:
☐ windings decoding/encoding ♐︎●︎♋︎♑︎❀︎♏︎📁︎🖮︎🖲︎📂︎♍︎♏︎⌛︎🖰︎♐︎🖮︎📂︎🖰︎📂︎🖰︎🖰︎♍︎📁︎🗏︎🖮︎🖰︎♌︎📂︎♍︎📁︎♋︎🗏︎♌︎♎︎♍︎🖲︎♏︎❝︎ f︎l︎a︎g︎{︎e︎0︎7︎9︎1︎c︎e︎6︎8︎f︎7︎1︎8︎1︎8︎8︎c︎0︎3︎7︎8︎b︎1︎c︎0︎a︎3︎b︎d︎c︎9︎e︎}︎
☐ magic method from cyberchef
☐ base 16
☐ base 36
☐ base 62
☐ base 91
Expand All @@ -43,6 +42,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
✔ base 16 @project(Methods)
✔ protobuf plugin @project(Plugins)
✔ string to l33tspeak. @project(Methods)
✔ run script loaded into chepy. script should be a function that takes one arg, and state is passed to arg. fixed function name in script should be passed that can be imported on method call @project(New ideas)
Expand Down
23 changes: 22 additions & 1 deletion chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import lazy_import
import binascii
import base64
import codecs
import html
import base58
import ujson
import yaml
yaml = lazy_import.lazy_module("yaml")
import regex as re
import hexdump
from ast import literal_eval
Expand Down Expand Up @@ -230,6 +231,26 @@ def base85_decode(self):
self.state = base64.a85decode(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def base16_encode(self):
"""Encode state in base16
Returns:
Chepy: The Chepy object.
"""
self.state = base64.b16encode(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def base16_decode(self):
"""Decode state in base16
Returns:
Chepy: The Chepy object.
"""
self.state = base64.b16decode(self._convert_to_bytes())
return self

@ChepyDecorators.call_stack
def base32_encode(self):
"""Encode as Base32
Expand Down
4 changes: 4 additions & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ from ..core import ChepyCore as ChepyCore, ChepyDecorators as ChepyDecorators
from chepy.modules.internal.constants import Encoding as Encoding
from typing import Any, Union

yaml: Any

class DataFormat(ChepyCore):
def __init__(self, *data: Any) -> None: ...
state: Any = ...
Expand All @@ -18,6 +20,8 @@ class DataFormat(ChepyCore):
def base58_decode(self): ...
def base85_encode(self): ...
def base85_decode(self): ...
def base16_encode(self): ...
def base16_decode(self): ...
def base32_encode(self): ...
def base32_decode(self): ...
def to_int(self): ...
Expand Down
26 changes: 16 additions & 10 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import codecs
import string
import itertools
import base64
import binascii
import jwt
import codecs
import itertools
import string

import lazy_import

jwt = lazy_import.lazy_module("jwt")
import pathlib
import ujson

import pycipher
import regex as re

import ujson
AES = lazy_import.lazy_module("Crypto.Cipher.AES")
ARC4 = lazy_import.lazy_module("Crypto.Cipher.ARC4")
DES = lazy_import.lazy_module("Crypto.Cipher.DES")
DES3 = lazy_import.lazy_module("Crypto.Cipher.DES3")
Blowfish = lazy_import.lazy_module("Crypto.Cipher.Blowfish")
from Crypto.Util.Padding import pad, unpad
from Crypto.Cipher import ARC4
from Crypto.Cipher import DES, DES3, AES
from Crypto.Cipher import Blowfish


from ..core import ChepyCore, ChepyDecorators
from .internal.constants import EncryptionConsts
from ..extras.combinatons import hex_chars
from .internal.constants import EncryptionConsts


class EncryptionEncoding(ChepyCore):
Expand Down
7 changes: 7 additions & 0 deletions chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ from ..extras.combinatons import hex_chars as hex_chars
from .internal.constants import EncryptionConsts as EncryptionConsts
from typing import Any

jwt: Any
AES: Any
ARC4: Any
DES: Any
DES3: Any
Blowfish: Any

class EncryptionEncoding(ChepyCore):
def __init__(self, *data: Any) -> None: ...
state: Any = ...
Expand Down
7 changes: 4 additions & 3 deletions chepy/modules/extractors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import lazy_import
import ujson
import regex as re
import jsonpath_rw
from urllib.parse import urlparse as _pyurlparse
from parsel import Selector
parsel = lazy_import.lazy_module("parsel")
from ..core import ChepyCore, ChepyDecorators


Expand All @@ -12,7 +13,7 @@ def __init__(self, *data):

def _parsel_obj(self):
"""Returns a parsel.Selector object"""
return Selector(self._convert_to_str())
return parsel.Selector(self._convert_to_str())

@ChepyDecorators.call_stack
def extract_hashes(self):
Expand Down Expand Up @@ -219,7 +220,7 @@ def xpath_selector(self, query: str, namespaces: str = None):
"Example Domain"
"""
self.state = (
Selector(self._convert_to_str(), namespaces=namespaces)
parsel.Selector(self._convert_to_str(), namespaces=namespaces)
.xpath(query)
.getall()
)
Expand Down
2 changes: 2 additions & 0 deletions chepy/modules/extractors.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ..core import ChepyCore as ChepyCore, ChepyDecorators as ChepyDecorators
from typing import Any

parsel: Any

class Extractors(ChepyCore):
def __init__(self, *data: Any) -> None: ...
state: Any = ...
Expand Down
51 changes: 32 additions & 19 deletions chepy/modules/hashing.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import lazy_import
import binascii
import hmac
import hashlib
import hashid


hashid = lazy_import.lazy_module("hashid")
from typing import Union

from typing_extensions import Literal
from Crypto.Hash import MD2, MD4, MD5, SHA512, SHA1, SHA256
from Crypto.Hash import keccak
from Crypto.Hash import SHAKE128, SHAKE256
from Crypto.Hash import RIPEMD
from Crypto.Hash import BLAKE2b, BLAKE2s
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Protocol.KDF import bcrypt as _crypto_bcrypt
from Crypto.Protocol.KDF import bcrypt_check as _crypto_bcrypt_check
from Crypto.Protocol.KDF import scrypt as _crypto_scrypt
from crccheck.crc import CrcArc, Crc32, Crc8

hmac = lazy_import.lazy_module("hmac")
MD2 = lazy_import.lazy_module("Crypto.Hash.MD2")
MD4 = lazy_import.lazy_module("Crypto.Hash.MD4")
MD5 = lazy_import.lazy_module("Crypto.Hash.MD5")
SHA512 = lazy_import.lazy_module("Crypto.Hash.SHA512")
SHA1 = lazy_import.lazy_module("Crypto.Hash.SHA1")
SHA256 = lazy_import.lazy_module("Crypto.Hash.SHA256")
keccak = lazy_import.lazy_module("Crypto.Hash.keccak")
SHAKE128 = lazy_import.lazy_module("Crypto.Hash.SHAKE128")
SHAKE256 = lazy_import.lazy_module("Crypto.Hash.SHAKE256")
RIPEMD = lazy_import.lazy_module("Crypto.Hash.RIPEMD")
BLAKE2s = lazy_import.lazy_module("Crypto.Hash.BLAKE2s")
BLAKE2b = lazy_import.lazy_module("Crypto.Hash.BLAKE2b")
from crccheck.crc import Crc8, Crc32, CrcArc
# from Crypto.Protocol.KDF import PBKDF2
KDF = lazy_import.lazy_module("Crypto.Protocol.KDF")
# from Crypto.Protocol.KDF import bcrypt as _crypto_bcrypt
# from Crypto.Protocol.KDF import bcrypt_check as _crypto_bcrypt_check
# from Crypto.Protocol.KDF import scrypt as _crypto_scrypt

from ..core import ChepyCore, ChepyDecorators

Expand Down Expand Up @@ -608,17 +621,17 @@ def derive_pbkdf2_key(
salt = binascii.unhexlify(salt)

if hash_type == "md5":
h = PBKDF2(password, salt, key_size, count=iterations, hmac_hash_module=MD5)
h = KDF.PBKDF2(password, salt, key_size, count=iterations, hmac_hash_module=MD5)
elif hash_type == "sha1":
h = PBKDF2(
h = KDF.PBKDF2(
password, salt, key_size, count=iterations, hmac_hash_module=SHA1
)
elif hash_type == "sha256":
h = PBKDF2(
h = KDF.PBKDF2(
password, salt, key_size, count=iterations, hmac_hash_module=SHA256
)
elif hash_type == "sha512":
h = PBKDF2(
h = KDF.PBKDF2(
password, salt, key_size, count=iterations, hmac_hash_module=SHA512
)
else: # pragma: no cover
Expand Down Expand Up @@ -648,7 +661,7 @@ def bcrypt_hash(self, rounds: int = 10):
Returns:
Chepy: The Chepy object.
"""
self.state = _crypto_bcrypt(self._convert_to_str(), cost=rounds)
self.state = KDF.bcrypt(self._convert_to_str(), cost=rounds)
return self

@ChepyDecorators.call_stack
Expand All @@ -669,7 +682,7 @@ def bcrypt_compare(self, hash: str):
True
"""
try:
if _crypto_bcrypt_check(self._convert_to_str(), hash) is None:
if KDF.bcrypt_check(self._convert_to_str(), hash) is None:
self.state = True
return self
else: # pragma: no cover
Expand Down Expand Up @@ -705,7 +718,7 @@ def scrypt_hash(
"f352f3374cf4e344dde4108b96985248"
"""
assert N < 32, "N must be less than 32"
self.state = _crypto_scrypt(
self.state = KDF.scrypt(
self._convert_to_bytes(), salt=salt, key_len=key_length, N=2 ** N, r=r, p=p
).hex()
return self
16 changes: 16 additions & 0 deletions chepy/modules/hashing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ from ..core import ChepyCore as ChepyCore, ChepyDecorators as ChepyDecorators
from typing import Any, Union
from typing_extensions import Literal as Literal

hashid: Any
hmac: Any
MD2: Any
MD4: Any
MD5: Any
SHA512: Any
SHA1: Any
SHA256: Any
keccak: Any
SHAKE128: Any
SHAKE256: Any
RIPEMD: Any
BLAKE2s: Any
BLAKE2b: Any
KDF: Any

class Hashing(ChepyCore):
def __init__(self, *data: Any) -> None: ...
state: Any = ...
Expand Down

0 comments on commit dfc3dee

Please sign in to comment.