Skip to content

Commit

Permalink
Add constructors where fields are private
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jan 20, 2022
1 parent 321cbc3 commit e3092da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
18 changes: 17 additions & 1 deletion umbral-pre/src/bindings_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ impl PublicKey {
}

impl PublicKey {
pub fn new(pk: umbral_pre::PublicKey) -> Self {
PublicKey(pk)
}

pub fn inner(&self) -> &umbral_pre::PublicKey {
&self.0
}
Expand Down Expand Up @@ -263,6 +267,10 @@ impl Capsule {
}

impl Capsule {
pub fn new(capsule: umbral_pre::Capsule) -> Self {
Capsule(capsule)
}

pub fn inner(&self) -> &umbral_pre::Capsule {
&self.0
}
Expand Down Expand Up @@ -347,6 +355,10 @@ impl VerifiedCapsuleFrag {
}

impl VerifiedCapsuleFrag {
pub fn new(verified_cfrag: umbral_pre::VerifiedCapsuleFrag) -> Self {
VerifiedCapsuleFrag(verified_cfrag)
}

pub fn inner(&self) -> umbral_pre::VerifiedCapsuleFrag {
self.0.clone()
}
Expand Down Expand Up @@ -378,7 +390,7 @@ impl CapsuleWithFrags {
ciphertext: &[u8],
) -> Result<Box<[u8]>, JsValue> {
let backend_cfrags: Vec<umbral_pre::VerifiedCapsuleFrag> =
self.cfrags.iter().map(|x| x.0.clone()).collect();
self.cfrags.iter().cloned().map(|x| x.0).collect();
umbral_pre::decrypt_reencrypted(
&receiving_sk.0,
&delegating_pk.0,
Expand Down Expand Up @@ -552,6 +564,10 @@ impl VerifiedKeyFrag {
}

impl VerifiedKeyFrag {
pub fn new(vkfrag: umbral_pre::VerifiedKeyFrag) -> Self {
Self(vkfrag)
}

pub fn inner(&self) -> &umbral_pre::VerifiedKeyFrag {
&self.0
}
Expand Down
6 changes: 3 additions & 3 deletions umbral-pre/src/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ mod tests {
// Empty cfrag vector
let result = capsule.open_reencrypted(&receiving_sk, &delegating_pk, &[]);
assert_eq!(
result.map(|x| x.as_secret().clone()),
result.map(|x| *x.as_secret()),
Err(OpenReencryptedError::NoCapsuleFrags)
);

Expand All @@ -334,15 +334,15 @@ mod tests {

let result = capsule.open_reencrypted(&receiving_sk, &delegating_pk, &mismatched_cfrags);
assert_eq!(
result.map(|x| x.as_secret().clone()),
result.map(|x| *x.as_secret()),
Err(OpenReencryptedError::MismatchedCapsuleFrags)
);

// Mismatched capsule
let (capsule2, _key_seed) = Capsule::from_public_key(&mut OsRng, &delegating_pk);
let result = capsule2.open_reencrypted(&receiving_sk, &delegating_pk, &cfrags);
assert_eq!(
result.map(|x| x.as_secret().clone()),
result.map(|x| *x.as_secret()),
Err(OpenReencryptedError::ValidationFailed)
);
}
Expand Down
1 change: 0 additions & 1 deletion umbral-pre/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ pub(crate) mod tests {

use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_json;

use super::Representation;
use crate::SerializableToArray;
Expand Down

0 comments on commit e3092da

Please sign in to comment.