forked from anoma/ferveo
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Update Python typings #139
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be90065
fix: python typings don't match runtime
piotr-roslaniec 4fcc7c0
chore(ci): remove maturin
piotr-roslaniec 50511ff
feat: replace FerveoVariant static methods with class atributed
piotr-roslaniec 7cbe65d
apply pr suggestions
piotr-roslaniec fbb97be
add api conversion method to FerveoVariant
piotr-roslaniec 6c1d4be
apply pr suggestions
piotr-roslaniec cea467e
add equality to FerveoVariant python bindings
piotr-roslaniec 06321d7
add __hash__ to FerveoVariant
piotr-roslaniec 0e7c561
rename FerveoVariant attributes
piotr-roslaniec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,4 +1,7 @@ | ||
use std::fmt::{Debug, Formatter}; | ||
use std::{ | ||
fmt, | ||
fmt::{Debug, Formatter}, | ||
}; | ||
|
||
use ferveo_common::serialization::{FromBytes, ToBytes}; | ||
use pyo3::{ | ||
|
@@ -235,9 +238,9 @@ pub fn encrypt( | |
|
||
#[pyfunction] | ||
pub fn combine_decryption_shares_simple( | ||
shares: Vec<DecryptionShareSimple>, | ||
decryption_shares: Vec<DecryptionShareSimple>, | ||
) -> SharedSecret { | ||
let shares = shares | ||
let shares = decryption_shares | ||
.iter() | ||
.map(|share| share.0.clone()) | ||
.collect::<Vec<_>>(); | ||
|
@@ -247,9 +250,9 @@ pub fn combine_decryption_shares_simple( | |
|
||
#[pyfunction] | ||
pub fn combine_decryption_shares_precomputed( | ||
shares: Vec<DecryptionSharePrecomputed>, | ||
decryption_shares: Vec<DecryptionSharePrecomputed>, | ||
) -> SharedSecret { | ||
let shares = shares | ||
let shares = decryption_shares | ||
.iter() | ||
.map(|share| share.0.clone()) | ||
.collect::<Vec<_>>(); | ||
|
@@ -268,25 +271,35 @@ pub fn decrypt_with_shared_secret( | |
} | ||
|
||
#[pyclass(module = "ferveo")] | ||
pub struct FerveoVariant {} | ||
#[derive(Clone)] | ||
pub struct FerveoVariant(pub(crate) api::FerveoVariant); | ||
|
||
#[pymethods] | ||
impl FerveoVariant { | ||
#[classattr] | ||
fn precomputed() -> &'static str { | ||
api::FerveoVariant::Precomputed.as_str() | ||
fn precomputed() -> FerveoVariant { | ||
api::FerveoVariant::Precomputed.into() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 - this seems much better than using strings. |
||
|
||
#[classattr] | ||
fn simple() -> &'static str { | ||
api::FerveoVariant::Simple.as_str() | ||
fn simple() -> FerveoVariant { | ||
api::FerveoVariant::Simple.into() | ||
} | ||
|
||
fn __str__(&self) -> String { | ||
self.0.to_string() | ||
} | ||
} | ||
|
||
impl FerveoVariant { | ||
pub fn inner_form_string(variant: &str) -> PyResult<api::FerveoVariant> { | ||
api::FerveoVariant::from_string(variant) | ||
.map_err(|err| FerveoPythonError::FerveoError(err).into()) | ||
impl From<api::FerveoVariant> for FerveoVariant { | ||
fn from(variant: api::FerveoVariant) -> Self { | ||
Self(variant) | ||
} | ||
} | ||
|
||
impl fmt::Display for FerveoVariant { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor nitpick I didn't pick up on earlier (and I know it's annoying), but can these be
SIMPLE
/PRECOMPUTED
orSimple
/Precomputed
. The lowercase looks a little weird in the Python code 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are class attributes, so I assumed they should be lowercase. I can fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Admittedly, it's a nitpick so if it is easy to fix/makes sense then great; if not, then you can ignore.
I didn't notice it until I saw it used in the 3171.