MdbClient

Struct MdbClient 

Source
pub struct MdbClient {
    pub url: String,
    /* private fields */
}
Expand description

Asynchronous Malware DB Client Configuration and connection

Fields§

§url: String

URL of the Malware DB server, including http and port number, ending without a slash

Implementations§

Source§

impl MdbClient

Source

pub fn new( url: String, api_key: String, cert_path: Option<PathBuf>, ) -> Result<Self>

MDB Client from components, doesn’t test connectivity

§Errors

Returns an error if a list of certificates was passed and any were not in the expected DER or PEM format or could not be parsed.

Source

pub async fn login( url: String, username: String, password: String, save: bool, cert_path: Option<PathBuf>, ) -> Result<Self>

Login to a server, optionally save the configuration file, and return a client object

§Errors

Returns an error if the server URL, username, or password were incorrect, or if a network issue occurred.

Source

pub async fn reset_key(&self) -> Result<()>

Reset one’s own API key to effectively logout & disable all clients who are using the key

§Errors

Returns an error if there was a network issue or the user wasn’t properly logged in.

Source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self>

Malware DB Client configuration loaded from a specified path

§Errors

Returns an error if the configuration file cannot be read, possibly because it doesn’t exist or due to a permission error or a parsing error.

Source

pub fn load() -> Result<Self>

Malware DB Client configuration from user’s home directory

On macOS, it will attempt to load this information in the Keychain, which isn’t required.

§Errors

Returns an error if the configuration file cannot be read, possibly because it doesn’t exist or due to a permission error or a parsing error.

Source

pub fn save(&self) -> Result<()>

Save Malware DB Client configuration to the user’s home directory.

On macOS, it will attempt to save this information in the Keychain, which isn’t required.

§Errors

Returns an error if there was a problem saving the configuration file.

Source

pub fn delete(&self) -> Result<()>

Delete the Malware DB client configuration file

§Errors

Returns an error if there isn’t a configuration file to delete, or if it cannot be deleted, possibly due to a permissions error.

Source

pub async fn server_info(&self) -> Result<ServerInfo>

Get information about the server, unauthenticated

§Errors

This may return an error if there’s a network situation.

Source

pub async fn supported_types(&self) -> Result<SupportedFileTypes>

Get file types supported by the server, unauthenticated

§Errors

This may return an error if there’s a network situation.

Source

pub async fn whoami(&self) -> Result<GetUserInfoResponse>

Get information about the user

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Source

pub async fn labels(&self) -> Result<Labels>

Get the sample labels known to the server

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Source

pub async fn sources(&self) -> Result<Sources>

Get the sources available to the current user

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Source

pub async fn submit( &self, contents: impl AsRef<[u8]>, file_name: impl AsRef<str>, source_id: u32, ) -> Result<bool>

Submit one file to MalwareDB: provide the contents, file name, and source ID

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Source

pub async fn submit_as_cbor( &self, contents: impl AsRef<[u8]>, file_name: impl AsRef<str>, source_id: u32, ) -> Result<bool>

Submit one file to MalwareDB as a Cbor object: provide the contents, file name, and source ID Experimental! May be removed at any point.

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Search for a file based on partial hash and/or partial file name, returns a list of hashes

§Errors
  • This may return an error if there’s a network situation or if the user is not logged in or the request isn’t valid
Source

pub async fn partial_search_labels_type( &self, partial_hash: Option<(PartialHashSearchType, String)>, name: Option<String>, response: PartialHashSearchType, labels: Option<Vec<String>>, file_type: Option<String>, magic: Option<String>, limit: u32, ) -> Result<SearchResponse>

Search for a file based on partial hash and/or partial file name, labels, file type; returns a list of hashes

§Errors
  • This may return an error if there’s a network situation or if the user is not logged in or the request isn’t valid

Return the next page from the search result

§Errors

Returns an error if there is a network problem, or pagination not available

Source

pub async fn retrieve(&self, hash: &str, cart: bool) -> Result<Vec<u8>>

Retrieve sample by hash, optionally in the CaRT format

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Source

pub async fn report(&self, hash: &str) -> Result<Report>

Fetch a report for a sample

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Source

pub async fn similar(&self, contents: &[u8]) -> Result<SimilarSamplesResponse>

Find similar samples in MalwareDB based on the contents of a given file. This does not submit the sample to MalwareDB.

§Errors

This may return an error if there’s a network situation or if the user is not logged in or not properly authorized to connect.

Trait Implementations§

Source§

impl Debug for MdbClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for MdbClient

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Drop for MdbClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Serialize for MdbClient

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Zeroize for MdbClient

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,