Skip to content

Commit

Permalink
renamed some fields in share
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Weber committed Aug 6, 2023
1 parent 4b5003b commit 67a0c7d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ To split a secret (file) into shares, execute one of the following examples.:
* Data is generated by an inline shell script and written to `STDOUT` (this approach uses process substitution): \
`agree interactive split -s <(printf "secret")`

This command is interactive and asks the user to provide data like share name, file path and optional password to encrypt the payload.
This command is interactive and asks the user to provide data like s hare name, file path and optional password to encrypt the share data.

### Restore a secret from _n_ shares

In the following example, the secret was split into 2 shares. We need to provide exactly two shares in order to restore the secret and write it to `STDOUT`.\
This command is interactive as it might prompt for the password of the share if it's payload is encrypted.
This command is interactive as it might prompt for the password of the share if it's share dataa is encrypted.

```
agree interactive restore -s ./share1.file -s ./share2.file
Expand Down
10 changes: 5 additions & 5 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ pub(crate) struct Archive {
/// This shares name.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// Some information about the secret.
#[serde(skip_serializing_if = "Option::is_none")]
pub secret: Option<SecretInfo>,
/// Some plain text comment.
#[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<String>,
/// Some information about the secret.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<SecretInfo>,

/// The actual share of the secret.
pub payload: Payload,
pub share: Share,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub(crate) enum Payload {
pub(crate) enum Share {
PlainBase64(String),
EncryptedBase64 { hash: Hash, data: String },
}
Expand Down
18 changes: 9 additions & 9 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use base64::Engine;
use ssss::SsssConfig;

use crate::{
archive::{Archive, Hash, Payload, SecretInfo},
archive::{Archive, Hash, SecretInfo, Share},
error::Error,
};

Expand Down Expand Up @@ -42,15 +42,15 @@ impl<'x> SSS<'x> {
version: "9f1e0683-7655-4f73-940a-38fa580b5725".to_owned(),
name: z.0.name.clone(),
comment: z.0.comment.clone(),
secret: if z.0.with_secret_info {
info: if z.0.with_secret_info {
Some(SecretInfo {
num_shares: blueprint.generate.len(),
threshold: blueprint.threshold,
})
} else {
None
},
payload: match &z.0.password {
share: match &z.0.password {
| Some(pw) => {
let mut salt = [0u8; 32];
OsRng::default().fill_bytes(&mut salt);
Expand All @@ -64,15 +64,15 @@ impl<'x> SSS<'x> {
.serialize()
.to_string();

Payload::EncryptedBase64 {
Share::EncryptedBase64 {
data: base64::engine::general_purpose::STANDARD
.encode(simplecrypt::encrypt(z.1.as_bytes(), pw.as_bytes())),
hash: Hash::Argon2id(hash),
}
},
| None => {
let encoded_payload = base64::engine::general_purpose::STANDARD.encode(z.1);
Payload::PlainBase64(encoded_payload)
let encoded_share = base64::engine::general_purpose::STANDARD.encode(z.1);
Share::PlainBase64(encoded_share)
},
},
};
Expand All @@ -91,9 +91,9 @@ impl<'x> SSS<'x> {
base64::engine::general_purpose::STANDARD.decode(s)?,
)?)?;

let data = match archive.payload {
| Payload::PlainBase64(v) => base64::engine::general_purpose::STANDARD.decode(v)?,
| Payload::EncryptedBase64 { hash, data } => {
let data = match archive.share {
| Share::PlainBase64(v) => base64::engine::general_purpose::STANDARD.decode(v)?,
| Share::EncryptedBase64 { hash, data } => {
let pw: String = dialoguer::Password::new()
.with_prompt(format!(
"Enter password for share (name: {})",
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async fn ask_for_share_data() -> Result<ShareGenInfo> {
};

let with_encryption = dialoguer::Confirm::new()
.with_prompt("Encrypt payload with password?")
.with_prompt("Encrypt share data with password?")
.interact()?;
let password: Option<String> = if with_encryption {
Some(dialoguer::Password::new().with_prompt("Enter password").interact()?)
Expand Down

0 comments on commit 67a0c7d

Please sign in to comment.