-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rename master secret to link secret
Signed-off-by: blu3beri <[email protected]>
- Loading branch information
1 parent
742e2d2
commit 0d7cfa2
Showing
40 changed files
with
435 additions
and
435 deletions.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::fmt; | ||
|
||
use crate::error::ConversionError; | ||
use serde::{Deserialize, Serialize}; | ||
use ursa::cl::{prover::Prover as UrsaProver, MasterSecret}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct LinkSecret { | ||
pub value: MasterSecret, | ||
} | ||
|
||
impl LinkSecret { | ||
#[inline] | ||
pub fn new() -> Result<Self, ConversionError> { | ||
let value = UrsaProver::new_master_secret().map_err(|err| { | ||
ConversionError::from_msg(format!("Error creating link secret: {err}")) | ||
})?; | ||
Ok(Self { value }) | ||
} | ||
|
||
pub fn try_clone(&self) -> Result<Self, ConversionError> { | ||
Ok(Self { | ||
value: self.value.try_clone().map_err(|e| e.to_string())?, | ||
}) | ||
} | ||
} | ||
|
||
impl fmt::Debug for LinkSecret { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("LinkSecret") | ||
.field(if cfg!(test) { &self.value } else { &"<hidden>" }) | ||
.finish() | ||
} | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod link_secret_tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn should_create_new_link_secret() { | ||
let link_secret = LinkSecret::new(); | ||
assert!(link_secret.is_ok()) | ||
} | ||
|
||
#[test] | ||
fn should_clone_link_secret() { | ||
let link_secret = LinkSecret::new().expect("Unable to create link secret"); | ||
let link_secret_value = link_secret.value.value().expect("Unable to extract value from link secret"); | ||
let cloned_link_secret = link_secret.try_clone().expect("Unable to clone link secret"); | ||
let cloned_link_secret_value = cloned_link_secret.value.value().expect("Unable to extract value from cloned link secret"); | ||
|
||
assert_eq!(link_secret_value, cloned_link_secret_value); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.