mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-09-01 14:59:18 +00:00
wrapped_secrets::generate_shares: make MIME type optional.
This commit is contained in:
committed by
Romain Ruetschi
parent
d3daa6825e
commit
cb44533c62
@ -16,19 +16,22 @@ use std::io;
|
|||||||
/// let secret = "These programs were never about terrorism: they’re about economic spying,
|
/// let secret = "These programs were never about terrorism: they’re about economic spying,
|
||||||
/// social control, and diplomatic manipulation. They’re about power.".to_string();
|
/// social control, and diplomatic manipulation. They’re about power.".to_string();
|
||||||
///
|
///
|
||||||
/// match generate_shares(7, 10, &secret.into_bytes(), "text/html", true){
|
/// match generate_shares(7, 10, &secret.into_bytes(), Some("text/html".to_string()), true){
|
||||||
/// Ok(shares) => {
|
/// Ok(shares) => {
|
||||||
/// // Do something with the shares
|
/// // Do something with the shares
|
||||||
/// },
|
/// },
|
||||||
/// Err(_) => {}// Deal with error}
|
/// Err(_) => {}// Deal with error}
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn generate_shares(k: u8, n: u8, secret: &[u8], mime_type: &str, sign_shares: bool) -> io::Result<Vec<String>> {
|
pub fn generate_shares(k: u8, n: u8, secret: &[u8], mime_type: Option<String>, sign_shares: bool) -> io::Result<Vec<String>> {
|
||||||
let mut rusty_secret = RustySecret::new();
|
let mut rusty_secret = RustySecret::new();
|
||||||
rusty_secret.set_version(RustySecretsVersions::INITIAL_RELEASE);
|
rusty_secret.set_version(RustySecretsVersions::INITIAL_RELEASE);
|
||||||
rusty_secret.set_mime_type(mime_type.to_owned());
|
|
||||||
rusty_secret.set_secret(secret.to_owned());
|
rusty_secret.set_secret(secret.to_owned());
|
||||||
|
|
||||||
|
for mt in mime_type {
|
||||||
|
rusty_secret.set_mime_type(mt);
|
||||||
|
}
|
||||||
|
|
||||||
sss::generate_shares(k, n, rusty_secret.write_to_bytes().unwrap().as_slice(), sign_shares)
|
sss::generate_shares(k, n, rusty_secret.write_to_bytes().unwrap().as_slice(), sign_shares)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,16 +14,17 @@ fn test_reasonable_splits() {
|
|||||||
.to_string()
|
.to_string()
|
||||||
.into_bytes();
|
.into_bytes();
|
||||||
|
|
||||||
let mime_type = "image/jpeg";
|
let mime_type = "image/jpeg".to_string();
|
||||||
|
|
||||||
for is_signing in &[true, false] {
|
for is_signing in &[true, false] {
|
||||||
for k in 1..max_shares {
|
for k in 1..max_shares {
|
||||||
for n in k..max_shares {
|
for n in k..max_shares {
|
||||||
let shares = wrapped_secrets::generate_shares(k, n, &secret, mime_type,*is_signing).unwrap();
|
let shares = wrapped_secrets::generate_shares(k, n, &secret, Some(mime_type.clone()), *is_signing).unwrap();
|
||||||
println!("Testing {} out-of- {}", k, n);
|
println!("Testing {} out-of- {}", k, n);
|
||||||
|
|
||||||
let s = wrapped_secrets::recover_secret(shares, *is_signing).unwrap();
|
let s = wrapped_secrets::recover_secret(shares, *is_signing).unwrap();
|
||||||
assert_eq!(s.get_secret().to_owned(), secret);
|
assert_eq!(s.get_secret().to_owned(), secret);
|
||||||
|
assert!(s.has_mime_type());
|
||||||
assert_eq!(mime_type, s.get_mime_type());
|
assert_eq!(mime_type, s.get_mime_type());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user