Skip to content

Commit

Permalink
Adds encrypt/decrypt to cli (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanced committed Apr 25, 2023
1 parent 1172ef7 commit 5737ac2
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 67 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Added
- Removed CLI alias `"e"` for enable-key and `"d"` for disable-key
- Renames DSA keyring `"key_pair"` to `"value"` (#52)
- Removes async from `navajo-cli`, making it sync for easier testing & resolving (#46)
- Each primitive's `KeyInfo` were renmaed from {Primitive}KeyInfo to `KeyInfo` (#53)
Expand Down
20 changes: 1 addition & 19 deletions navajo-cli/src/aad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ impl Debug for Aad {
}
}

// impl From<&String> for Aad {
// fn from(s: &String) -> Self {
// Self(s.to_string())
// }
// }

// impl TryFrom<&OsStr> for Aad {
// type Error = anyhow::Error;

// fn try_from(s: &OsStr) -> Result<Self, Self::Error> {
// let v = s
// .to_str()
// .ok_or(anyhow::anyhow!("failed to convert {s:?} to utf8"))?
// .to_string();
// Ok(Self(v))
// }
// }

impl FromStr for Aad {
type Err = anyhow::Error;

Expand All @@ -56,7 +38,7 @@ impl FromStr for Aad {
_ => bail!("unknown Secret Store scheme: {}", secret.scheme()),
}
} else {
todo!()
Ok(Self(navajo::Aad(sensitive::Bytes::from(s.as_bytes()))))
}
}
}
48 changes: 47 additions & 1 deletion navajo-cli/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use clap::ValueEnum;
use navajo::Kind;
use serde::Deserialize;

#[derive(Clone, Debug, PartialEq, Eq, ValueEnum, strum::Display, strum::EnumIter, Deserialize)]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, ValueEnum, strum::Display, strum::EnumIter, Deserialize,
)]
#[serde(try_from = "&str")]
pub enum Algorithm {
// ------------------------------------------
Expand Down Expand Up @@ -354,3 +356,47 @@ impl TryFrom<Algorithm> for navajo::mac::Algorithm {
}
}
}
impl From<navajo::aead::Algorithm> for Algorithm {
fn from(value: navajo::aead::Algorithm) -> Self {
match value {
navajo::aead::Algorithm::Aes128Gcm => Algorithm::Aes_128_Gcm,
navajo::aead::Algorithm::Aes256Gcm => Algorithm::Aes_256_Gcm,
navajo::aead::Algorithm::ChaCha20Poly1305 => Algorithm::Chacha20Poly1305,
navajo::aead::Algorithm::XChaCha20Poly1305 => Algorithm::Xchacha20Poly1305,
}
}
}

impl From<navajo::daead::Algorithm> for Algorithm {
fn from(value: navajo::daead::Algorithm) -> Self {
match value {
navajo::daead::Algorithm::Aes256Siv => Algorithm::Aes_256_Siv,
}
}
}
impl From<navajo::dsa::Algorithm> for Algorithm {
fn from(value: navajo::dsa::Algorithm) -> Self {
match value {
navajo::dsa::Algorithm::Es256 => Algorithm::Es256,
navajo::dsa::Algorithm::Es384 => Algorithm::Es384,
navajo::dsa::Algorithm::Ed25519 => Algorithm::Ed25519,
}
}
}
impl From<navajo::mac::Algorithm> for Algorithm {
fn from(value: navajo::mac::Algorithm) -> Self {
match value {
navajo::mac::Algorithm::Blake3 => Algorithm::Blake3,
navajo::mac::Algorithm::Sha256 => Algorithm::Sha2_256,
navajo::mac::Algorithm::Sha384 => Algorithm::Sha2_384,
navajo::mac::Algorithm::Sha512 => Algorithm::Sha2_512,
navajo::mac::Algorithm::Sha3_256 => Algorithm::Sha3_256,
navajo::mac::Algorithm::Sha3_224 => Algorithm::Sha3_224,
navajo::mac::Algorithm::Sha3_384 => Algorithm::Sha3_384,
navajo::mac::Algorithm::Sha3_512 => Algorithm::Sha3_512,
navajo::mac::Algorithm::Aes128 => Algorithm::Aes_128,
navajo::mac::Algorithm::Aes192 => Algorithm::Aes_192,
navajo::mac::Algorithm::Aes256 => Algorithm::Aes_256,
}
}
}
Loading

0 comments on commit 5737ac2

Please sign in to comment.