Skip to content

Commit

Permalink
explicit parameter types
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
  • Loading branch information
andrewwhitehead committed Aug 10, 2023
1 parent e205189 commit 1fbbcbf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:

strategy:
matrix:
architecture: [linux-aarch64, linux-x86_64, windows-x86_64]
python-version: ["3.8"]
include:
- architecture: linux-aarch64
Expand Down Expand Up @@ -79,8 +80,7 @@ jobs:
- name: Checkout library
uses: actions/checkout@v3
with:
repository: "andrewwwhitehead/indy-blssignatures-rs"
ref: "upd/bls"
repository: "hyperledger/indy-blssignatures-rs"
path: "build"

- name: Build
Expand Down Expand Up @@ -109,14 +109,7 @@ jobs:
shell: sh
run: |
pip install pytest dist/*
echo "-- Test SQLite in-memory --"
python -m pytest --log-cli-level=WARNING -k "not contention"
echo "-- Test SQLite file DB --"
TEST_STORE_URI=sqlite://test.db python -m pytest --log-cli-level=WARNING -k "not contention"
if [ -n "$POSTGRES_URL" ]; then
echo "-- Test Postgres DB --"
TEST_STORE_URI="$POSTGRES_URL" python -m pytest --log-cli-level=WARNING -k "not contention"
fi
python -m pytest --log-cli-level=DEBUG
working-directory: wrappers/python
env:
no_proxy: "*" # python issue 30385
Expand All @@ -128,6 +121,12 @@ jobs:
auditwheel show wrappers/python/dist/* | tee auditwheel.log
grep -q manylinux_2_17_ auditwheel.log
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: python-${{ matrix.plat-name }}
path: dist/*

- if: |
github.event_name == 'release' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
Expand Down
32 changes: 19 additions & 13 deletions indy_bls/bls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import logging

from ctypes import POINTER, c_void_p, byref, c_size_t, c_ubyte, c_bool
from ctypes import POINTER, byref, c_bool, c_char_p, c_int32, c_int64, c_ubyte, c_void_p
from typing import Optional
from weakref import finalize

from .lib import do_call
Expand Down Expand Up @@ -56,7 +57,7 @@ def as_bytes(self):
LOGGER.debug("BlsEntity.as_bytes: >>> self: %r", self)

xbytes = POINTER(c_ubyte)()
xbytes_len = c_size_t()
xbytes_len = c_int32()

do_call(
self.as_bytes_handler, self.c_instance, byref(xbytes), byref(xbytes_len)
Expand Down Expand Up @@ -103,20 +104,22 @@ class SignKey(BlsEntity):
free_handler = "indy_bls_sign_key_free"

@classmethod
def new(cls, seed):
def new(cls, seed: Optional[bytes] = None):
"""
Create and return a random (or seeded from seed) BLS sign key.
:param: seed - Optional seed.
:return: BLS sign key
"""
LOGGER.debug("SignKey::new: >>>")
if seed and not isinstance(seed, bytes):
raise ValueError("seed must be a bytes instance")

c_instance = c_void_p()
do_call(
cls.new_handler,
seed,
len(seed) if seed is not None else 0,
c_char_p(seed),
c_int32(len(seed) if seed is not None else 0),
byref(c_instance),
)

Expand Down Expand Up @@ -218,7 +221,10 @@ def new(cls, signatures):

c_instance = c_void_p()
do_call(
cls.new_handler, signature_c_instances, len(signatures), byref(c_instance)
cls.new_handler,
signature_c_instances,
c_int32(len(signatures)),
byref(c_instance),
)

res = cls(c_instance)
Expand All @@ -244,8 +250,8 @@ def sign(message, sign_key):
c_instance = c_void_p()
do_call(
"indy_bls_sign",
message,
len(message),
c_char_p(message),
c_int64(len(message)),
sign_key.c_instance,
byref(c_instance),
)
Expand Down Expand Up @@ -278,8 +284,8 @@ def verify(signature, message, ver_key, gen):
do_call(
"indy_bls_verify",
signature.c_instance,
message,
len(message),
c_char_p(message),
c_int64(len(message)),
ver_key.c_instance,
gen.c_instance,
byref(valid),
Expand Down Expand Up @@ -347,10 +353,10 @@ def verify_multi_sig(multi_sig, message, ver_keys, gen):
do_call(
"indy_bls_verify_multi_sig",
multi_sig.c_instance,
message,
len(message),
c_char_p(message),
c_int64(len(message)),
ver_key_c_instances,
len(ver_keys),
c_int32(len(ver_keys)),
gen.c_instance,
byref(valid),
)
Expand Down

0 comments on commit 1fbbcbf

Please sign in to comment.