From 4889d6b9b2ef193600e0e0475ff4207b8decdac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Wed, 19 Jun 2024 17:15:53 +0200 Subject: [PATCH] Use a specific error type for each invalid version error --- src/error.rs | 6 ++++-- src/storage.rs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 61b1ba7..f225373 100644 --- a/src/error.rs +++ b/src/error.rs @@ -32,8 +32,10 @@ pub enum Error { ParsingEncodedDataInvalidPartLen(usize, usize), #[error("parsing error: encoded data: invalid timestamp: {0:?}")] ParsingEncodedDataInvalidTimestamp(Vec), - #[error("parsing error: encoded data: invalid version")] - ParsingEncodedDataInvalidVersion, + #[error("parsing error: encoded data: invalid IKML version")] + ParsingEncodedDataInvalidIkmlVersion, + #[error("parsing error: encoded data: invalid encrypted data version")] + ParsingEncodedDataInvalidEncVersion, #[error("parsing error: scheme: {0}: unknown scheme")] ParsingSchemeUnknownScheme(crate::scheme::SchemeSerializeType), #[error("unable to generate random values: {0}")] diff --git a/src/storage.rs b/src/storage.rs index 0115ecb..4e6bcac 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -59,7 +59,7 @@ pub(crate) fn encode_cipher( pub(crate) fn decode_ikm_list(data: &str) -> Result { let data = data .strip_prefix(crate::STORAGE_IKML_VERSION) - .ok_or(Error::ParsingEncodedDataInvalidVersion)?; + .ok_or(Error::ParsingEncodedDataInvalidIkmlVersion)?; let v: Vec<&str> = data.split(STORAGE_SEPARATOR).collect(); if v.is_empty() { return Err(Error::ParsingEncodedDataInvalidIkmListLen(v.len())); @@ -85,7 +85,7 @@ pub(crate) fn decode_ikm_list(data: &str) -> Result { pub(crate) fn decode_cipher(data: &str) -> Result<(IkmId, EncryptedData, Option)> { let data = data .strip_prefix(crate::STORAGE_ENC_VERSION) - .ok_or(Error::ParsingEncodedDataInvalidVersion)?; + .ok_or(Error::ParsingEncodedDataInvalidEncVersion)?; let mut v: Vec<&str> = data.split(STORAGE_SEPARATOR).collect(); let time_period = if v.len() == NB_PARTS + 1 { match v.pop() {