Struct armorlib::scan_object::ScanObject [] [src]

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

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

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.

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.

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.

The BinaryObject that the ScanObject contains.

Methods

impl ScanObject
[src]

[src]

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")))
);