aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--src/cipherstring.rs37
-rw-r--r--src/error.rs7
3 files changed, 41 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23c35ce..f6bf057 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## Unreleased
+
+### Fixed
+
+* More improved error messages.
+
## [0.4.0] - 2020-05-28
### Added
diff --git a/src/cipherstring.rs b/src/cipherstring.rs
index 94284d5..7aaaf9f 100644
--- a/src/cipherstring.rs
+++ b/src/cipherstring.rs
@@ -20,12 +20,16 @@ impl CipherString {
pub fn new(s: &str) -> Result<Self> {
let parts: Vec<&str> = s.split('.').collect();
if parts.len() != 2 {
- return Err(Error::InvalidCipherString);
+ return Err(Error::InvalidCipherString {
+ reason: "couldn't find type".to_string(),
+ });
}
let ty = parts[0].as_bytes();
if ty.len() != 1 {
- return Err(Error::InvalidCipherString);
+ return Err(Error::UnimplementedCipherStringType {
+ ty: parts[0].to_string(),
+ });
}
let ty = ty[0] - b'0';
@@ -35,7 +39,12 @@ impl CipherString {
2 => {
let parts: Vec<&str> = contents.split('|').collect();
if parts.len() < 2 || parts.len() > 3 {
- return Err(Error::InvalidCipherString);
+ return Err(Error::InvalidCipherString {
+ reason: format!(
+ "type 2 cipherstring with {} parts",
+ parts.len()
+ ),
+ });
}
let iv = base64::decode(parts[0])
@@ -62,7 +71,9 @@ impl CipherString {
.context(crate::error::InvalidBase64)?;
Ok(Self::Asymmetric { ciphertext })
}
- _ => Err(Error::InvalidCipherString),
+ _ => Err(Error::UnimplementedCipherStringType {
+ ty: ty.to_string(),
+ }),
}
}
@@ -115,7 +126,11 @@ impl CipherString {
.decrypt_vec(ciphertext)
.context(crate::error::Decrypt)
}
- _ => Err(Error::InvalidCipherString),
+ _ => Err(Error::InvalidCipherString {
+ reason:
+ "found an asymmetric cipherstring, expecting symmetric"
+ .to_string(),
+ }),
}
}
@@ -142,7 +157,11 @@ impl CipherString {
.context(crate::error::Decrypt)?;
Ok(res)
}
- _ => Err(Error::InvalidCipherString),
+ _ => Err(Error::InvalidCipherString {
+ reason:
+ "found an asymmetric cipherstring, expecting symmetric"
+ .to_string(),
+ }),
}
}
@@ -175,7 +194,11 @@ impl CipherString {
Ok(res)
}
- _ => Err(Error::InvalidCipherString),
+ _ => Err(Error::InvalidCipherString {
+ reason:
+ "found a symmetric cipherstring, expecting asymmetric"
+ .to_string(),
+ }),
}
}
}
diff --git a/src/error.rs b/src/error.rs
index 5a95fec..131d5b9 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -40,8 +40,8 @@ pub enum Error {
#[snafu(display("invalid base64"))]
InvalidBase64 { source: base64::DecodeError },
- #[snafu(display("invalid cipherstring"))]
- InvalidCipherString,
+ #[snafu(display("invalid cipherstring: {}", reason))]
+ InvalidCipherString { reason: String },
#[snafu(display("invalid value for $EDITOR: {}", editor.to_string_lossy()))]
InvalidEditor { editor: std::ffi::OsString },
@@ -164,6 +164,9 @@ pub enum Error {
providers: Vec<crate::api::TwoFactorProviderType>,
},
+ #[snafu(display("unimplemented cipherstring type: {}", ty))]
+ UnimplementedCipherStringType { ty: String },
+
#[snafu(display("error writing to pinentry stdin"))]
WriteStdin { source: tokio::io::Error },
}