mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/pv_core: Fix the argument order in 'LengthMismatch'
Fix the ordering of the parameters in 'TryFrom<Confidential<Vec<u8> for
Confidential<[u8; N>'. While at it, convert 'LengthMismatch' error to a
named struct.
Fixes: 7608cf2de4 ("rust/confidential: Add `From` and `Into` for confidential byes arrays/vectors")
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
24e285ce02
commit
8c23e09a60
@@ -760,7 +760,10 @@ mod tests {
|
||||
|
||||
assert!(matches!(
|
||||
SymKey::try_from_data(SymKeyType::Aes256Gcm, Confidential::new([0x4u8; 33].into())),
|
||||
Err(Error::PvCore(PvCoreError::LengthMismatch(33, 32)))
|
||||
Err(Error::PvCore(PvCoreError::LengthMismatch {
|
||||
expected: 32,
|
||||
actual: 33
|
||||
}))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,10 @@ impl<const N: usize> TryFrom<Confidential<Vec<u8>>> for Confidential<[u8; N]> {
|
||||
TryInto::<[u8; N]>::try_into(value.0.clone()).unwrap(),
|
||||
))
|
||||
} else {
|
||||
Err(Error::LengthMismatch(len, N))
|
||||
Err(Error::LengthMismatch {
|
||||
expected: N,
|
||||
actual: len,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,7 +261,13 @@ mod test {
|
||||
|
||||
let result: Result<Confidential<[u8; 101]>, Error> =
|
||||
Confidential::new(data.clone()).try_into();
|
||||
assert!(matches!(result, Err(Error::LengthMismatch(100, 101))));
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(Error::LengthMismatch {
|
||||
expected: 101,
|
||||
actual: 100
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -82,8 +82,8 @@ pub enum Error {
|
||||
#[error("Cannot decode hex string")]
|
||||
InvHexStringChar { source: std::num::ParseIntError },
|
||||
|
||||
#[error("Expected size {0}, found {1}")]
|
||||
LengthMismatch(usize, usize),
|
||||
#[error("Expected size {expected}, actual {actual}")]
|
||||
LengthMismatch { expected: usize, actual: usize },
|
||||
}
|
||||
|
||||
/// Error cases for I/O operations
|
||||
|
||||
Reference in New Issue
Block a user