Skip to content

Commit

Permalink
respond to RFCs in PR nucypher#48
Browse files Browse the repository at this point in the history
  • Loading branch information
KPrasch committed Apr 30, 2023
1 parent a89b7f0 commit 784a8dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
15 changes: 10 additions & 5 deletions nucypher-core-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,20 @@ impl ThresholdDecryptionRequest {
ciphertext: &[u8], // TODO use ferveo Ciphertext type
conditions: Option<&Conditions>,
context: Option<&Context>,
) -> Self {
) -> PyResult<Self> {
let ferveo_variant: FerveoVariant;
if variant > 1 {
return Err(PyValueError::new_err(
"Invalid ThresholdDecryptionRequest variant",
));
}
match variant {
0 => ferveo_variant = FerveoVariant::SIMPLE,
1 => ferveo_variant = FerveoVariant::PRECOMPUTED,
_ => panic!("Invalid variant"),
_ => unreachable!(),
}

Self {
Ok(Self {
backend: nucypher_core::ThresholdDecryptionRequest::new(
id,
ciphertext,
Expand All @@ -668,7 +673,7 @@ impl ThresholdDecryptionRequest {
context.map(|context| context.backend.clone()).as_ref(),
&ferveo_variant,
),
}
})
}

#[getter]
Expand Down Expand Up @@ -732,7 +737,7 @@ impl ThresholdDecryptionResponse {
#[new]
pub fn new(decryption_share: &[u8]) -> Self {
ThresholdDecryptionResponse {
backend: nucypher_core::ThresholdDecryptionResponse::new(decryption_share.into()),
backend: nucypher_core::ThresholdDecryptionResponse::new(decryption_share),
}
}

Expand Down
4 changes: 2 additions & 2 deletions nucypher-core-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ impl ThresholdDecryptionResponse {
#[wasm_bindgen(constructor)]
pub fn new(decryption_share: &[u8]) -> Result<ThresholdDecryptionResponse, Error> {
Ok(Self(nucypher_core::ThresholdDecryptionResponse::new(
decryption_share.into(),
decryption_share,
)))
}

#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = decryptionShare)]
pub fn decryption_share(&self) -> Box<[u8]> {
self.0.decryption_share.clone()
}
Expand Down
13 changes: 9 additions & 4 deletions nucypher-core/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloc::boxed::Box;
use alloc::string::String;

use serde::{Deserialize, Serialize};
use umbral_pre::serde_bytes;

use crate::conditions::{Conditions, Context};

Expand All @@ -10,7 +11,7 @@ use crate::versioning::{
};

/// The ferveo variant to use for the decryption share derivation.
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Copy, Clone)]
pub enum FerveoVariant {
/// the simple variant requires n/n shares to decrypt
SIMPLE,
Expand All @@ -24,6 +25,7 @@ pub struct ThresholdDecryptionRequest {
/// The ID of the ritual.
pub ritual_id: u16,
/// The ciphertext to generate a decryption share for.
#[serde(with = "serde_bytes::as_base64")]
pub ciphertext: Box<[u8]>,
/// A blob of bytes containing decryption conditions for this message.
pub conditions: Option<Conditions>,
Expand All @@ -47,7 +49,7 @@ impl ThresholdDecryptionRequest {
ciphertext: ciphertext.to_vec().into(),
conditions: conditions.cloned(),
context: context.cloned(),
variant: variant.clone(),
variant: *variant,
}
}
}
Expand Down Expand Up @@ -80,13 +82,16 @@ impl<'a> ProtocolObject<'a> for ThresholdDecryptionRequest {}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
pub struct ThresholdDecryptionResponse {
/// The decryption share to include in the response.
#[serde(with = "serde_bytes::as_base64")]
pub decryption_share: Box<[u8]>,
}

impl ThresholdDecryptionResponse {
/// Creates and a new decryption response.
pub fn new(decryption_share: Box<[u8]>) -> Self {
ThresholdDecryptionResponse { decryption_share }
pub fn new(decryption_share: &[u8]) -> Self {
ThresholdDecryptionResponse {
decryption_share: decryption_share.to_vec().into(),
}
}
}

Expand Down
1 change: 1 addition & 0 deletions nucypher-core/src/node_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct NodeMetadataPayload {
/// The node's encrypting key.
pub encrypting_key: PublicKey,
/// Ferveo public key to use for DKG participation.
#[serde(with = "serde_bytes::as_base64")]
pub ferveo_public_key: Box<[u8]>, // TODO use ferveo PublicKey?
/// The node's SSL certificate (serialized in DER format).
#[serde(with = "serde_bytes::as_base64")]
Expand Down

0 comments on commit 784a8dc

Please sign in to comment.