Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
job-ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.13"
Expand All @@ -36,7 +36,7 @@ jobs:
continue-on-error: true
if: (github.actor != 'dependabot[bot]')
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- run: |
semgrep ci --verbose \
--config p/ci \
Expand All @@ -51,7 +51,7 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# sudo python setup.py install clean --all
- uses: actions/checkout@v6
- uses: actions/checkout@v7

- name: pip-install-test
run: |
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

[![License](https://img.shields.io/github/license/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/LabNow-ai/aloha-python/build.yml?branch=main)](https://github.com/LabNow-ai/aloha-python/actions)
[![Join the Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/LabNow-ai/)
[![PyPI version](https://img.shields.io/pypi/v/aloha)](https://pypi.python.org/pypi/aloha/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/aloha)](https://pepy.tech/badge/aloha/)
[![Code Activity](https://img.shields.io/github/commit-activity/m/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/pulse)
Expand All @@ -15,7 +14,10 @@
Please generously STAR★ our project or donate to us!
[![GitHub Starts](https://img.shields.io/github/stars/LabNow-ai/aloha-python.svg?label=Stars&style=social)](https://github.com/LabNow-ai/aloha-python/stargazers)

- To contribute or talk to a human: [![Open an Issue on GitHub](https://img.shields.io/github/issues/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/issues) [![Join the Discord Chat](https://img.shields.io/badge/Discuss_on-Discord-green)](https://discord.gg/kHUzgQxgbJ)
- To understand the package, read the [📚docs](https://aloha-python.readthedocs.io/) or [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/LabNow-ai/lab-foundation)

- To contribute or talk to a human: [![Open an Issue on GitHub](https://img.shields.io/github/issues/LabNow-ai/aloha-python)](https://github.com/LabNow-ai/aloha-python/issues) [![Join the Discord Chat](https://img.shields.io/badge/Discuss_on-Discord-green)](https://discord.gg/kHUzgQxgbJ) [![Join the Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/LabNow-ai/)


## Getting started

Expand Down
15 changes: 15 additions & 0 deletions src/aloha/encrypt/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ def hash_obj(obj):
"""Hash an arbitrary JSON-serializable object."""
s = json.dumps(obj, sort_keys=True, ensure_ascii=False, default=str)
return hashlib.md5(s.encode()).hexdigest()


def hash_base62(s: str, length: int = 6) -> str:
"""Return a Base62-encoded hash of a string with specified length."""
assert length > 0 and length <= 11, "Length must be between 1 and 11 for Base62 encoding."

CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
digest = hashlib.sha256(s.encode()).digest() # 32 bytes = 256 bits
# Convert the digest to an integer and then to Base62
num = int.from_bytes(digest, "big")
result = []
for _ in range(length):
result.append(CHARS[num % 62])
num //= 62
return "".join(reversed(result))
4 changes: 2 additions & 2 deletions src/aloha/encrypt/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from ..logger import LOG

LOG.debug("Using pyjwt == %s" % jwt.__version__.__str__())
LOG.debug("Using pyjwt == %s" % str(jwt.__version__))


def encode(secret_key: str, payload: dict, headers: dict = None, **kwargs):
def encode(secret_key: str, payload: dict, headers: dict | None = None, **kwargs):
"""Encode a payload into a JWT token."""
token = jwt.encode(payload=payload, key=secret_key, headers=headers, **kwargs)
return token
Expand Down
7 changes: 3 additions & 4 deletions src/aloha/encrypt/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def main():
y_dec = rsa_dec.decrypt_with_private_key(y_bin, key_private=key_pri)
y_txt = y_dec.decode("UTF-8")

print(
"[test {i_case} success = {status}] {src} -> {enc}".format(
i_case=i, status=(y_txt == str_src), src=y_txt, enc=x_txt
)
msg = "[test {i_case} success = {status}] {src} -> {enc}".format(
i_case=i, status=(y_txt == str_src), src=y_txt, enc=x_txt
)
print(msg)