-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move project to `uv` Add typing Add pre-commit Reformat code Make code more secure Update workflow python_simplified.yml Update workflow python_detailed.yml Signed-off-by: andrew000 <[email protected]> * Replace `pipe operator` to `Union`, to support py3.9 Bump deps Signed-off-by: andrew000 <[email protected]> * Resolve conflicts Bump deps Signed-off-by: andrew000 <[email protected]> * Fix `_fields_` in `Signature` Add stream handler to logger Signed-off-by: andrew000 <[email protected]> * Add stream handler to logger in rand.py and kem.py Signed-off-by: andrew000 <[email protected]> * Add stream handler to logger in sig.py Signed-off-by: andrew000 <[email protected]> * Updated examples * Bump `ruff`, `0.9.3` -> `0.9.4` Signed-off-by: andrew000 <[email protected]> * Change type hint of `_fields_` from `list` to `Sequence` Signed-off-by: andrew000 <[email protected]> * Added COM812 to tools.ruff.lint.ignore Signed-off-by: Vlad Gheorghiu <[email protected]> --------- Signed-off-by: andrew000 <[email protected]> Signed-off-by: Vlad Gheorghiu <[email protected]> Co-authored-by: Vlad Gheorghiu <[email protected]>
- Loading branch information
Showing
17 changed files
with
717 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,5 @@ pip-selfcheck.json | |
pyvenv.cfg | ||
|
||
# vim | ||
*.swp | ||
*.swp | ||
/uv.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
fail_fast: false | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: "trailing-whitespace" | ||
- id: "check-case-conflict" | ||
- id: "check-merge-conflict" | ||
- id: "debug-statements" | ||
- id: "end-of-file-fixer" | ||
- id: "mixed-line-ending" | ||
args: [ "--fix", "crlf" ] | ||
types: | ||
- python | ||
- yaml | ||
- toml | ||
- text | ||
- id: "detect-private-key" | ||
- id: "check-yaml" | ||
- id: "check-toml" | ||
- id: "check-json" | ||
|
||
- repo: https://github.com/charliermarsh/ruff-pre-commit | ||
rev: v0.9.4 | ||
hooks: | ||
- id: ruff | ||
args: [ "--fix" ] | ||
files: "oqs" | ||
|
||
- id: ruff-format | ||
files: "oqs" | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
name: isort (python) | ||
files: "oqs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Code checker/formatter | ||
# | ||
# Pre-requisites | ||
# | ||
# isort | ||
# mypy | ||
# ruff | ||
# uv | ||
|
||
src-dir = oqs | ||
tests-dir = tests | ||
examples-dir = examples | ||
|
||
.PHONY lint: | ||
lint: | ||
echo "Running ruff..." | ||
uv run ruff check --config pyproject.toml --diff $(src-dir) $(tests-dir) $(examples-dir) | ||
|
||
.PHONY format: | ||
format: | ||
echo "Running ruff check with --fix..." | ||
uv run ruff check --config pyproject.toml --fix --unsafe-fixes $(src-dir) $(tests-dir) $(examples-dir) | ||
|
||
echo "Running ruff..." | ||
uv run ruff format --config pyproject.toml $(src-dir) $(tests-dir) $(examples-dir) | ||
|
||
echo "Running isort..." | ||
uv run isort --settings-file pyproject.toml $(src-dir) $(tests-dir) $(examples-dir) | ||
|
||
.PHONE mypy: | ||
mypy: | ||
echo "Running MyPy..." | ||
uv run mypy --config-file pyproject.toml $(src-dir) | ||
|
||
.PHONY outdated: | ||
outdated: | ||
uv tree --outdated --universal | ||
|
||
.PHONY sync: | ||
sync: | ||
uv sync --extra dev --extra lint |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
# Various RNGs Python example | ||
|
||
import logging | ||
import platform # to learn the OS we're on | ||
from sys import stdout | ||
|
||
import oqs.rand as oqsrand # must be explicitly imported | ||
from oqs import oqs_version, oqs_python_version | ||
from oqs import oqs_python_version, oqs_version | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
logger.addHandler(logging.StreamHandler(stdout)) | ||
|
||
print("liboqs version:", oqs_version()) | ||
print("liboqs-python version:", oqs_python_version()) | ||
logger.info("liboqs version: %s", oqs_version()) | ||
logger.info("liboqs-python version: %s", oqs_python_version()) | ||
|
||
oqsrand.randombytes_switch_algorithm("system") | ||
print( | ||
"{:17s}".format("System (default):"), | ||
" ".join("{:02X}".format(x) for x in oqsrand.randombytes(32)), | ||
logger.info( | ||
"System (default): %s", | ||
" ".join(f"{x:02X}" for x in oqsrand.randombytes(32)), | ||
) | ||
|
||
# We do not yet support OpenSSL under Windows | ||
if platform.system() != "Windows": | ||
oqsrand.randombytes_switch_algorithm("OpenSSL") | ||
print( | ||
"{:17s}".format("OpenSSL:"), | ||
" ".join("{:02X}".format(x) for x in oqsrand.randombytes(32)), | ||
logger.info( | ||
"OpenSSL: %s", | ||
" ".join(f"{x:02X}" for x in oqsrand.randombytes(32)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,42 @@ | ||
# Signature Python example | ||
|
||
import logging | ||
from pprint import pformat | ||
from sys import stdout | ||
|
||
import oqs | ||
from pprint import pprint | ||
|
||
print("liboqs version:", oqs.oqs_version()) | ||
print("liboqs-python version:", oqs.oqs_python_version()) | ||
print("Enabled signature mechanisms:") | ||
sigs = oqs.get_enabled_sig_mechanisms() | ||
pprint(sigs, compact=True) | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
logger.addHandler(logging.StreamHandler(stdout)) | ||
|
||
logger.info("liboqs version: %s", oqs.oqs_version()) | ||
logger.info("liboqs-python version: %s", oqs.oqs_python_version()) | ||
logger.info( | ||
"Enabled signature mechanisms:\n%s", | ||
pformat(oqs.get_enabled_sig_mechanisms(), compact=True), | ||
) | ||
|
||
message = "This is the message to sign".encode() | ||
message = b"This is the message to sign" | ||
|
||
# Create signer and verifier with sample signature mechanisms | ||
sigalg = "ML-DSA-44" | ||
with oqs.Signature(sigalg) as signer: | ||
with oqs.Signature(sigalg) as verifier: | ||
print("\nSignature details:") | ||
pprint(signer.details) | ||
with oqs.Signature(sigalg) as signer, oqs.Signature(sigalg) as verifier: | ||
logger.info("Signature details:\n%s", pformat(signer.details)) | ||
|
||
# Signer generates its keypair | ||
signer_public_key = signer.generate_keypair() | ||
# Optionally, the secret key can be obtained by calling export_secret_key() | ||
# and the signer can later be re-instantiated with the key pair: | ||
# secret_key = signer.export_secret_key() | ||
# Signer generates its keypair | ||
signer_public_key = signer.generate_keypair() | ||
# Optionally, the secret key can be obtained by calling export_secret_key() | ||
# and the signer can later be re-instantiated with the key pair: | ||
# secret_key = signer.export_secret_key() | ||
|
||
# Store key pair, wait... (session resumption): | ||
# signer = oqs.Signature(sigalg, secret_key) | ||
# Store key pair, wait... (session resumption): | ||
# signer = oqs.Signature(sigalg, secret_key) | ||
|
||
# Signer signs the message | ||
signature = signer.sign(message) | ||
# Signer signs the message | ||
signature = signer.sign(message) | ||
|
||
# Verifier verifies the signature | ||
is_valid = verifier.verify(message, signature, signer_public_key) | ||
# Verifier verifies the signature | ||
is_valid = verifier.verify(message, signature, signer_public_key) | ||
|
||
print("\nValid signature?", is_valid) | ||
logger.info("Valid signature? %s", is_valid) |
Oops, something went wrong.