Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [EPIC] Fizzy: Integrates conditions and context fields into MessageKit, ReencryptionRequest, RetrievalKit, with first rust tests #26

Merged
merged 15 commits into from
Sep 10, 2022
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.0
current_version = 0.4.0-alpha.0
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<stage>[^.]*)\.(?P<devnum>\d+))?
Expand Down
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

Under Construction

## [0.4.0-alpha.0] 2022-09-07

### Fixed

- Fixed the type annotation for `signer` in `generate_kfrags()` in Python type stubs. ([#28])

### Added

- `conditions` and `context` to `ReencryptionRequest` with python/wasm bindings to expose them.
- `conditions` to `MessageKit` and `RetrievalKit` with python/wasm bindings to expose them.
- rust-native tests for these new attributes and getters

[#24]: https://github.com/nucypher/nucypher-core/pull/24
[#25]: https://github.com/nucypher/nucypher-core/pull/25
[#26]: https://github.com/nucypher/nucypher-core/pull/26
[#28]: https://github.com/nucypher/nucypher-core/pull/28


## [0.3.0] - 2022-08-16

### Changed
Expand All @@ -29,7 +40,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The Python module `nucypher_core.umbral` now exports `KeyFrag`. ([#20])
- `Display` impl for `HRAC` and `FleetStateChecksum`, and exposed it in the Python and WASM bindings. ([#22])


[#17]: https://github.com/nucypher/nucypher-core/pull/17
[#20]: https://github.com/nucypher/nucypher-core/pull/20
[#22]: https://github.com/nucypher/nucypher-core/pull/22
Expand Down
2 changes: 1 addition & 1 deletion nucypher-core-python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "nucypher-core-python"
authors = ["Bogdan Opanchuk <bogdan@opanchuk.net>"]
version = "0.3.0"
version = "0.4.0-alpha.0"
edition = "2018"

[lib]
Expand Down
2 changes: 2 additions & 0 deletions nucypher-core-python/nucypher_core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class RetrievalKit:

queried_addresses: Set[bytes]

conditions: Optional[bytes]

@staticmethod
def from_bytes(data: bytes) -> RetrievalKit:
...
Expand Down
14 changes: 12 additions & 2 deletions nucypher-core-python/replace_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,25 @@ def get_version():
lines = f.readlines()

for line in lines:
m = re.match(r'^version = "(\d+\.\d+\.\d+)"$', line)
pattern = re.compile(
r'^version = ' # starts with "version = "
r'"(' # main capturing group
r'\d+\.\d+\.\d+' # standard semver
r'(?:-[a-z]+\.\d+)?' # optional non-capturing group for prereleases
r')"' # ends main capturing group
r'$' # nothing more
)
m = pattern.search(line)
if m:
version = m.group(1)
version = m.groups(0)[0]
print(f'Found version {version}')
break
else:
raise RuntimeError("Cannot find the package version")

return version


def relative_to_published():

version = get_version()
Expand Down
2 changes: 1 addition & 1 deletion nucypher-core-python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
description="Protocol structures of Nucypher network",
long_description=long_description,
long_description_content_type="text/markdown",
version="0.3.0",
version="0.4.0-alpha.0",
author="Bogdan Opanchuk",
author_email="bogdan@opanchuk.net",
url="https://github.com/nucypher/nucypher-core/tree/master/nucypher-core-python",
Expand Down
57 changes: 53 additions & 4 deletions nucypher-core-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
}

//
// MessageKit
//
//

#[pyclass(module = "nucypher_core")]
Expand Down Expand Up @@ -111,9 +111,17 @@ impl MessageKit {
}

#[new]
pub fn new(policy_encrypting_key: &PublicKey, plaintext: &[u8]) -> Self {
pub fn new(
policy_encrypting_key: &PublicKey,
plaintext: &[u8],
conditions: Option<&[u8]>,
) -> Self {
Self {
backend: nucypher_core::MessageKit::new(&policy_encrypting_key.backend, plaintext),
backend: nucypher_core::MessageKit::new(
&policy_encrypting_key.backend,
plaintext,
conditions,
),
}
}

Expand Down Expand Up @@ -147,6 +155,14 @@ impl MessageKit {
backend: self.backend.capsule,
}
}

#[getter]
fn conditions(&self) -> Option<&[u8]> {
self.backend
.conditions
.as_ref()
.map(|boxed_condition| boxed_condition.as_ref())
}
}

//
Expand Down Expand Up @@ -461,6 +477,8 @@ impl ReencryptionRequest {
encrypted_kfrag: &EncryptedKeyFrag,
publisher_verifying_key: &PublicKey,
bob_verifying_key: &PublicKey,
conditions: Option<&[u8]>,
context: Option<&[u8]>,
) -> Self {
let capsules_backend = capsules
.iter()
Expand All @@ -473,6 +491,8 @@ impl ReencryptionRequest {
&encrypted_kfrag.backend,
&publisher_verifying_key.backend,
&bob_verifying_key.backend,
conditions,
context,
),
}
}
Expand Down Expand Up @@ -514,6 +534,22 @@ impl ReencryptionRequest {
.collect::<Vec<_>>()
}

#[getter]
fn conditions(&self) -> Option<&[u8]> {
self.backend
.conditions
.as_ref()
.map(|boxed_conditions| boxed_conditions.as_ref())
}

#[getter]
fn context(&self) -> Option<&[u8]> {
self.backend
.context
.as_ref()
.map(|boxed_context| boxed_context.as_ref())
}

#[staticmethod]
pub fn from_bytes(data: &[u8]) -> PyResult<Self> {
from_bytes(data)
Expand Down Expand Up @@ -640,13 +676,18 @@ impl RetrievalKit {
pub fn new(
capsule: &Capsule,
queried_addresses: BTreeSet<[u8; nucypher_core::Address::SIZE]>,
conditions: Option<&[u8]>,
) -> Self {
let addresses_backend = queried_addresses
.iter()
.map(nucypher_core::Address::new)
.collect::<Vec<_>>();
Self {
backend: nucypher_core::RetrievalKit::new(&capsule.backend, addresses_backend),
backend: nucypher_core::RetrievalKit::new(
&capsule.backend,
addresses_backend,
conditions,
),
}
}

Expand All @@ -666,6 +707,14 @@ impl RetrievalKit {
.collect::<BTreeSet<_>>()
}

#[getter]
fn conditions(&self) -> Option<&[u8]> {
self.backend
.conditions
.as_ref()
.map(|boxed_condition| boxed_condition.as_ref())
}

#[staticmethod]
pub fn from_bytes(data: &[u8]) -> PyResult<Self> {
from_bytes(data)
Expand Down
2 changes: 1 addition & 1 deletion nucypher-core-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nucypher-core-wasm"
version = "0.3.0"
version = "0.4.0-alpha.0"
authors = [
"Bogdan Opanchuk <bogdan@opanchuk.net>",
"Piotr Roslaniec <p.roslaniec@gmail.com>"
Expand Down
2 changes: 1 addition & 1 deletion nucypher-core-wasm/package.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Bogdan Opanchuk <bogdan@opanchuk.net>"
],
"description": "NuCypher network core data structures",
"version": "0.3.0",
"version": "0.4.0-alpha.0",
"license": "GPL-3.0-only",
"repository": {
"type": "git",
Expand Down
Loading