Enum malwaredb_server::db::DatabaseType

source ·
pub enum DatabaseType {
    Postgres(Postgres),
    SQLite(Sqlite),
}
Expand description

Database handle for SQLite or Postgres

Variants§

§

Postgres(Postgres)

Postgres database

§

SQLite(Sqlite)

SQLite database

Implementations§

source§

impl DatabaseType

source

pub async fn from_string(arg: &str) -> Result<Self>

Get a database connection from a configuration string

source

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

Set the compression flag

source

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

Unset the compression flag, does not go and decompress files already compressed!

source

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

Set the flag allowing uploads to VirusTotal.

source

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

Set the flag preventing uploads to VirusTotal.

source

pub async fn files_without_vt_records(&self, limit: i32) -> Result<Vec<String>>

Get the SHA-256 hashes of the files which don’t have VT records

source

pub async fn store_vt_record( &self, results: &ScanResultAttributes, ) -> Result<()>

Store the VT results: AV hits and detailed report, or lack of any AV hits

source

pub async fn get_vt_stats(&self) -> Result<VtStats>

Quick statistics regarding the data contained for VT information for our samples

source

pub async fn get_config(&self) -> Result<MDBConfig>

Get the configuration which is stored in the database

source

pub async fn authenticate(&self, uname: &str, password: &str) -> Result<String>

Check user credentials, return API key. Generate if it doesn’t exist.

source

pub async fn get_uid(&self, apikey: &str) -> Result<i32>

Get the user’s ID from their API key

source

pub async fn db_info(&self) -> Result<DatabaseInformation>

Retrieve information about the database

source

pub async fn get_user_info(&self, uid: i32) -> Result<GetUserInfoResponse>

Retrieve the names of the groups and sources the user is part of and has access to

source

pub async fn get_user_sources(&self, uid: i32) -> Result<Sources>

Retrieve the source information available to the specified user

source

pub async fn reset_own_api_key(&self, uid: i32) -> Result<()>

Let the user clear their own API key to log out from all systems

source

pub async fn get_known_data_types(&self) -> Result<Vec<FileType>>

Retrieve the supported data type information

source

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

Get all labels from MalwareDB

source

pub async fn get_type_id_for_bytes(&self, data: &[u8]) -> Result<i32>

Get the corresponding type ID for a buffer representing a file

source

pub async fn allowed_user_source(&self, uid: i32, sid: i32) -> Result<bool>

Check that a user has been granted access data for the specific source

source

pub async fn user_is_admin(&self, uid: i32) -> Result<bool>

Check to see if the user is an administrator. The user must be a member of the the admin group (group ID 0), or a one group below (a group with the parent group id of 0).

source

pub async fn add_file( &self, meta: &FileMetadata, known_type: KnownType<'_>, uid: i32, sid: i32, ftype: i32, parent: Option<i64>, ) -> Result<bool>

Add a file’s metadata to the database, returning true if this is a new entry

source

pub async fn retrieve_sample(&self, uid: i32, hash: &HashType) -> Result<String>

Retrieve the SHA-256 hash of the sample while checking that the user is permitted to access to it

source

pub async fn get_sample_report( &self, uid: i32, hash: &HashType, ) -> Result<Report>

Retrieve a report for a given sample, if allowed.

source

pub async fn find_similar_samples( &self, uid: i32, sim: &[(SimilarityHashType, String)], ) -> Result<Vec<SimilarSample>>

Given a collection of similarity hashes, find samples which are similar.

source

pub async fn add_file_encryption_key(&self, key: &FileEncryption) -> Result<u32>

Add an encryption key to the database, set it as the default, and return the key ID

source

pub async fn get_encryption_key_names_ids( &self, ) -> Result<Vec<(u32, EncryptionOption)>>

Get the key ID and algorithm names

source

pub async fn create_user( &self, uname: &str, fname: &str, lname: &str, email: &str, password: Option<String>, organisation: Option<String>, ) -> Result<u64>

Create a user account, return the user ID.

source

pub async fn reset_api_keys(&self) -> Result<u64>

Clear all API keys, either in case of suspected activity, or part of policy

source

pub async fn set_password(&self, uname: &str, password: &str) -> Result<()>

Set a user’s password

source

pub async fn list_users(&self) -> Result<Vec<User>>

Get the complete list of users

source

pub async fn group_id_from_name(&self, name: &str) -> Result<i32>

Get the ID of a group from name

source

pub async fn edit_group( &self, gid: i32, name: &str, desc: &str, parent: Option<i32>, ) -> Result<()>

Update the record for a group

source

pub async fn list_groups(&self) -> Result<Vec<Group>>

Get the complete list of groups

source

pub async fn add_user_to_group(&self, uid: i32, gid: i32) -> Result<()>

Grant a user membership to a group, both by id.

source

pub async fn add_group_to_source(&self, gid: i32, sid: i32) -> Result<()>

Grand a group access to a source, both by id.

source

pub async fn create_group( &self, name: &str, description: &str, parent: Option<i32>, ) -> Result<i32>

Create a new group, returning the group ID

source

pub async fn list_sources(&self) -> Result<Vec<Source>>

Get the complete list of sources

source

pub async fn create_source( &self, name: &str, description: Option<&str>, url: Option<&str>, date: DateTime<Local>, releasable: bool, malicious: Option<bool>, ) -> Result<i32>

Create a source, returning the source ID

source

pub async fn edit_user( &self, uid: i32, uname: &str, fname: &str, lname: &str, email: &str, ) -> Result<()>

Edit a user account setting the specified field values

source

pub async fn deactivate_user(&self, uid: i32) -> Result<()>

Deactivate, but don’t delete, a user’s account

source

pub async fn file_types_counts(&self) -> Result<HashMap<String, u32>>

File types and number of files per type

source

pub async fn create_label(&self, name: &str, parent: Option<i64>) -> Result<u64>

Create a new label

source

pub async fn edit_label( &self, id: u64, name: &str, parent: Option<u64>, ) -> Result<()>

Edit a label name or parent

source

pub async fn label_id_from_name(&self, name: &str) -> Result<u64>

Return the ID for a given label name

Trait Implementations§

source§

impl Debug for DatabaseType

source§

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

Formats the value using the given formatter. Read more

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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