Skip to content

Commit

Permalink
refactor: replace DeserializationError with type alias
Browse files Browse the repository at this point in the history
The error enum had only 1 element and we can replace it with
alias for simplicity.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
  • Loading branch information
ShadowCurse committed Dec 11, 2024
1 parent 8a9f711 commit 2e11953
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/vmm/src/seccomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::HashMap;
use std::io::Read;
use std::sync::Arc;

use bincode::{DefaultOptions, Error as BincodeError, Options};
use bincode::{DefaultOptions, Options};

/// Each BPF instruction is 8 bytes long and 4 byte aligned.
/// This alignment needs to be satisfied in order for a BPF code to be accepted
Expand All @@ -21,6 +21,9 @@ pub type BpfProgramRef<'a> = &'a [BpfInstruction];
/// Type that associates a thread category to a BPF program.
pub type BpfThreadMap = HashMap<String, Arc<BpfProgram>>;

/// Binary filter deserialization errors.
pub type DeserializationError = bincode::Error;

/// Retrieve empty seccomp filters.
pub fn get_empty_filters() -> BpfThreadMap {
let mut map = BpfThreadMap::new();
Expand All @@ -30,13 +33,6 @@ pub fn get_empty_filters() -> BpfThreadMap {
map
}

/// Binary filter deserialization errors.
#[derive(Debug, thiserror::Error, displaydoc::Display)]
pub enum DeserializationError {
/// Bincode deserialization failed: {0}
Bincode(BincodeError),
}

/// Deserialize binary with bpf filters
pub fn deserialize_binary<R: Read>(
reader: R,
Expand All @@ -50,8 +46,7 @@ pub fn deserialize_binary<R: Read>(
.deserialize_from::<R, HashMap<String, BpfProgram>>(reader),
// No limit is the default.
None => bincode::deserialize_from::<R, HashMap<String, BpfProgram>>(reader),
}
.map_err(DeserializationError::Bincode)?;
}?;

Ok(result
.into_iter()
Expand Down Expand Up @@ -169,7 +164,7 @@ mod tests {
// Binary limit too low.
assert!(matches!(
deserialize_binary(&bytes[..], Some(20)).unwrap_err(),
DeserializationError::Bincode(error)
error
if error.to_string() == "the size limit has been reached"
));

Expand Down

0 comments on commit 2e11953

Please sign in to comment.