Use a specific error type for each invalid version error
This commit is contained in:
parent
44cc9179ca
commit
4889d6b9b2
2 changed files with 6 additions and 4 deletions
|
@ -32,8 +32,10 @@ pub enum Error {
|
|||
ParsingEncodedDataInvalidPartLen(usize, usize),
|
||||
#[error("parsing error: encoded data: invalid timestamp: {0:?}")]
|
||||
ParsingEncodedDataInvalidTimestamp(Vec<u8>),
|
||||
#[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}")]
|
||||
|
|
|
@ -59,7 +59,7 @@ pub(crate) fn encode_cipher(
|
|||
pub(crate) fn decode_ikm_list(data: &str) -> Result<InputKeyMaterialList> {
|
||||
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<InputKeyMaterialList> {
|
|||
pub(crate) fn decode_cipher(data: &str) -> Result<(IkmId, EncryptedData, Option<u64>)> {
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue