Skip to content

Commit

Permalink
Remove unnecessary/excession make_factory method from SessionSecretFa…
Browse files Browse the repository at this point in the history
…ctory.
  • Loading branch information
derekpierre committed Jun 6, 2023
1 parent 8e7a4fa commit 253dfde
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
4 changes: 0 additions & 4 deletions nucypher-core-python/nucypher_core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,3 @@ class SessionSecretFactory:

def make_key(self, label: bytes) -> SessionStaticSecret:
...

def make_factory(self, label: bytes) -> RequestKeyFactory:
...

6 changes: 0 additions & 6 deletions nucypher-core-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,6 @@ impl SessionSecretFactory {
}
}

pub fn make_factory(&self, label: &[u8]) -> SessionSecretFactory {
SessionSecretFactory {
backend: self.backend.make_factory(label),
}
}

fn __str__(&self) -> String {
self.backend.to_string()
}
Expand Down
5 changes: 0 additions & 5 deletions nucypher-core-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,6 @@ impl SessionSecretFactory {
SessionStaticSecret(self.0.make_key(label))
}

#[wasm_bindgen(js_name = makeFactory)]
pub fn make_factory(&self, label: &[u8]) -> Self {
Self(self.0.make_factory(label))
}

#[allow(clippy::inherent_to_string)]
#[wasm_bindgen(js_name = toString)]
pub fn to_string(&self) -> String {
Expand Down
19 changes: 8 additions & 11 deletions nucypher-core/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ pub mod session {
type SessionSecretFactorySeed = GenericArray<u8, SessionSecretFactorySeedSize>;

/// Error thrown when invalid random seed provided for creating key factory.
#[derive(Debug)]
pub struct InvalidSessionSecretFactorySeedLength;

impl fmt::Display for InvalidSessionSecretFactorySeedLength {
Expand Down Expand Up @@ -319,14 +320,6 @@ pub mod session {
ChaCha20Rng::from_seed(<[u8; 32]>::try_from(seed.as_secret().as_slice()).unwrap());
SessionStaticSecret::random_from_rng(&mut rng)
}

/// Creates a `SessionSecretFactory` deterministically from the given label.
pub fn make_factory(&self, label: &[u8]) -> Self {
let prefix = b"SESSION_SECRET_FACTORY_DERIVATION/";
let info = [prefix, label].concat();
let derived_seed = kdf::<SessionSecretFactorySeedSize>(self.0.as_secret(), Some(&info));
Self(derived_seed)
}
}

impl fmt::Display for SessionSecretFactory {
Expand Down Expand Up @@ -590,6 +583,7 @@ mod tests {
};

use generic_array::typenum::Unsigned;
use rand_core::RngCore;

use crate::dkg::session::SessionStaticSecret;
use crate::dkg::{
Expand Down Expand Up @@ -652,9 +646,12 @@ mod tests {
assert_ne!(requester_public_key, not_same_requester_public_key);

// ensure that two secret factories with the same seed generate the same keys
let secret_factory_label = b"seeded_secret_factory_label".to_vec().into_boxed_slice();
let seeded_secret_factory_1 = secret_factory.make_factory(&secret_factory_label.as_ref());
let seeded_secret_factory_2 = secret_factory.make_factory(&secret_factory_label.as_ref());
let mut secret_factory_seed = [0u8; 32];
rand::thread_rng().fill_bytes(&mut secret_factory_seed);
let seeded_secret_factory_1 =
SessionSecretFactory::from_secure_randomness(&secret_factory_seed).unwrap();
let seeded_secret_factory_2 =
SessionSecretFactory::from_secure_randomness(&secret_factory_seed).unwrap();

let key_label = b"seeded_factory_key_label".to_vec().into_boxed_slice();
let sk_1 = seeded_secret_factory_1.make_key(&key_label);
Expand Down

0 comments on commit 253dfde

Please sign in to comment.