wrapped_secrets::generate_shares: make MIME type optional.

This commit is contained in:
Romain Ruetschi
2017-08-03 17:02:33 +02:00
committed by Romain Ruetschi
parent d3daa6825e
commit cb44533c62
2 changed files with 9 additions and 5 deletions

View File

@ -16,19 +16,22 @@ use std::io;
/// let secret = "These programs were never about terrorism: theyre about economic spying,
/// social control, and diplomatic manipulation. Theyre 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) => {
/// // Do something with the shares
/// },
/// 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();
rusty_secret.set_version(RustySecretsVersions::INITIAL_RELEASE);
rusty_secret.set_mime_type(mime_type.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)
}

View File

@ -14,16 +14,17 @@ fn test_reasonable_splits() {
.to_string()
.into_bytes();
let mime_type = "image/jpeg";
let mime_type = "image/jpeg".to_string();
for is_signing in &[true, false] {
for k in 1..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);
let s = wrapped_secrets::recover_secret(shares, *is_signing).unwrap();
assert_eq!(s.get_secret().to_owned(), secret);
assert!(s.has_mime_type());
assert_eq!(mime_type, s.get_mime_type());
}
}