Struct ScanObject

Source
pub struct ScanObject {
    pub metadata: HashMap<String, HashMap<String, String>>,
    pub filetype: Option<String>,
    pub detected_filetypes: Vec<String>,
    pub binary_object: BinaryObject,
}
Expand description

A struct that represents a BinaryObject (with associated filetype) that has been preprocessed and therefore contains metadata. This is the object that is passed to ScanModules.

This object is typically only created by the coordinator, and there are few cases in which it would be necessary to create this object in your own library. Still, it is public so that future versions of the library might be more extendable.

Fields§

§metadata: HashMap<String, HashMap<String, String>>

A HashMap that represents data created by the preprocessors. Each root key string corresponds to the ID of the preprocessor. The value of each root pair is a HashMap created by the preprocessor. Refer to each preprocessor’s documentation for information about its respective keys and values.

§filetype: Option<String>

The filetype of the data. This is passed in by the user, and is not determined by any preprocessor. Instead, it is extracted by the CLI or provided by the bound program. It should not be trusted; a file may advertise itself with its extension as a .pdf file but may in fact be a .tiff file, for example.

Because there is no guarantee that any filetype will be given by the user (for example, when all that is passed to form the root BinaryObject is a Vec<u8>), there is a possibility of absence.

§detected_filetypes: Vec<String>

The filetypes of the data, as detected by the special filetype preprocessor. Multiple filetypes may exist, because, for example, a txt file may also be a yaml file.

§binary_object: BinaryObject

The BinaryObject that the ScanObject contains.

Implementations§

Source§

impl ScanObject

Source

pub fn get_metadata(&self, path: &str) -> Result<&String, ArmorlibError>

Get the given key created by the given preprocessor, where the key and preprocessor are denoted in the format <preprocessor/key>. Will return the HashMap if the preprocessor is present, ortherwise a ProcessingError::MissingPreprocessor error will be returned.

§Examples
use armorlib::{ScanObject, ArmorlibError, BinaryObject};
#[macro_use]
extern crate maplit;
// given the scan object with the name `scan_object`, we can easily access its metadata:
assert_eq!(
    // use a `match` statement in your own code for safety
    scan_object.get_metadata("preprocessor/key_name").unwrap(),
    &String::from("value")
);

// if we try to access metadata from a preprocessor that doesn't exist,
// we'll get a `MissingPreprocessor` error.
assert_eq!(
    scan_object.get_metadata("fake_preprocessor/key_name"),
    Err(ArmorlibError::MissingPreprocessor(String::from(
        "fake_preprocessor"
    )))
);

// if we try to access metadata that doesn't exist from a preprocessor that does, we'll
// get a `MissingMetadata` error.
assert_eq!(
    scan_object.get_metadata("preprocessor/fake_key"),
    Err(ArmorlibError::MissingMetadata(String::from("preprocessor/fake_key")))
);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.