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

Wrap conditions and context in newtypes #33

Merged
merged 8 commits into from
Sep 18, 2022
Merged

Conversation

fjarri
Copy link
Contributor

@fjarri fjarri commented Sep 11, 2022

  • Added Context and Conditions newtypes.
  • Changed context and conditions to be strings instead of bytes.
  • Support v1.0 (pre-conditions) MessageKit, RetrievalKit and ReencryptionRequest
  • Some internal boilerplate removal (get rid of AsBackend and FromBackend and replace them with derived AsRef and From)

Note: because of a strange quirk of wasm-bindgen (rustwasm/wasm-bindgen#2370) constructors taking Option<Conditions> or Option<Context> consume their arguments in JS. This is already an issue in Umbral (nucypher/rust-umbral#25).

@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2022

Codecov Report

Merging #33 (062da2d) into master (dd09a87) will increase coverage by 0.51%.
The diff coverage is 24.56%.

@@            Coverage Diff             @@
##           master      #33      +/-   ##
==========================================
+ Coverage   15.61%   16.12%   +0.51%     
==========================================
  Files          11       12       +1     
  Lines         429      465      +36     
==========================================
+ Hits           67       75       +8     
- Misses        362      390      +28     
Impacted Files Coverage Δ
nucypher-core/src/message_kit.rs 0.00% <0.00%> (ø)
nucypher-core/src/retrieval_kit.rs 0.00% <0.00%> (ø)
nucypher-core/src/reencryption.rs 31.81% <28.57%> (-4.55%) ⬇️
nucypher-core/src/conditions.rs 66.66% <66.66%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@fjarri fjarri changed the title [WIP] Wrap various bytestrings in newtypes Wrap conditions and context in newtypes Sep 14, 2022
Comment on lines +8 to +12
def __init__(self, conditions: str):
...

@classmethod
def from_string(cls, conditions: str) -> Conditions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between these two constructors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a difference in Rust (allocating vs non-allocating), and this structure is just mapped here. I guess we could safely remove it from Python and JS bindings.

pub struct Conditions(String);

impl Conditions {
/// Creates a new conditions object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment likely to be helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have any better ideas. We could say here that it's supposed to be a JSON string, but nothing in nucypher-core really acts on that assumption...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But do we need any comment to explain that new makes a new object?

Copy link
Contributor Author

@fjarri fjarri Sep 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do because of #![warn(missing_docs)]. It's easier to just write something than to add a specific exclusion in this case.

@fjarri fjarri mentioned this pull request Sep 18, 2022
@KPrasch KPrasch merged commit f6a6163 into nucypher:master Sep 18, 2022
@fjarri fjarri deleted the newtypes branch September 18, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants