Skip to content

Commit

Permalink
Change: rust: cargo fmt
Browse files Browse the repository at this point in the history
Run cargo fmt to enforce formatting guidelines.
  • Loading branch information
nichtsfrei committed Feb 2, 2024
1 parent c1af13d commit 8bc64f1
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 58 deletions.
4 changes: 0 additions & 4 deletions .github/test.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions rust/nasl-interpreter/src/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later







#[cfg(test)]
mod tests {
use std::collections::HashMap;
Expand Down
9 changes: 3 additions & 6 deletions rust/nasl-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::{collections::HashMap, io};

use nasl_syntax::{
IdentifierType, LoadError, NaslValue, StatementKind::*, Token, TokenCategory, Statement,
IdentifierType, LoadError, NaslValue, Statement, StatementKind::*, Token, TokenCategory,
};
use storage::StorageError;

Expand Down Expand Up @@ -50,7 +50,6 @@ where
}
}


fn include(&mut self, name: &Statement) -> InterpretResult {
match self.resolve(name)? {
NaslValue::String(key) => {
Expand All @@ -70,7 +69,7 @@ where
_ => Err(InterpretError::unsupported(name, "string")),
}
}

/// Tries to interpret a statement and retries n times on a retry error
///
/// When encountering a retrievable error:
Expand Down Expand Up @@ -215,14 +214,12 @@ where
}
NoOp => Ok(NaslValue::Null),
EoF => Ok(NaslValue::Null),
AttackCategory => {
AttackCategory => {
match statement.as_token().category() {
TokenCategory::Identifier(IdentifierType::ACT(cat)) => Ok(NaslValue::AttackCategory(*cat)),
_ => unreachable!("AttackCategory must have ACT token but got {:?}, this is an bug within the lexer.", statement.as_token())

}


},
Continue => Ok(NaslValue::Continue),
Break => Ok(NaslValue::Break),
Expand Down
1 change: 0 additions & 1 deletion rust/nasl-syntax/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ fn infix_binding_power(op: &Operation) -> Option<(u8, u8)> {
Some(res)
}


enum InFixState {
NoInfix,
ReturnContinue(Statement),
Expand Down
3 changes: 2 additions & 1 deletion rust/nasl-syntax/src/variable_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use crate::{
error::SyntaxError,
lexer::{End, Lexer},
token::{Category}, Statement, StatementKind,
token::Category,
Statement, StatementKind,
};

pub(crate) trait CommaGroup {
Expand Down
17 changes: 6 additions & 11 deletions rust/openvasd/src/controller/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! All known paths must be handled in the entrypoint function.

use std::{fmt::Display, sync::Arc, marker::PhantomData};
use std::{fmt::Display, marker::PhantomData, sync::Arc};

use super::{context::Context, ClientIdentifier};

Expand Down Expand Up @@ -126,7 +126,6 @@ pub struct EntryPoint<S, DB, R> {
pub ctx: Arc<Context<S, DB>>,
pub cid: Arc<ClientIdentifier>,
_phantom: PhantomData<R>,

}

impl<S, DB, R> EntryPoint<S, DB, R> {
Expand All @@ -136,12 +135,9 @@ impl<S, DB, R> EntryPoint<S, DB, R> {
cid,
_phantom: PhantomData,
}

}

}


impl<S, DB, R> hyper::service::Service<Request<R>> for EntryPoint<S, DB, R>
where
S: ScanStarter
Expand Down Expand Up @@ -264,7 +260,8 @@ where
}
}
(&Method::POST, Scans(None)) => {
match crate::request::json_request::<models::Scan, _>(&ctx.response, req).await {
match crate::request::json_request::<models::Scan, _>(&ctx.response, req).await
{
Ok(mut scan) => {
if scan.scan_id.is_some() {
return Ok(ctx
Expand Down Expand Up @@ -389,9 +386,7 @@ where
};

match ctx.db.get_results(&id, begin, end).await {
Ok(results) => {
Ok(ctx.response.ok_byte_stream(results).await)
},
Ok(results) => Ok(ctx.response.ok_byte_stream(results).await),
Err(crate::storage::Error::NotFound) => {
Ok(ctx.response.not_found("scans/results", &id))
}
Expand All @@ -412,7 +407,8 @@ where
None => Ok(ctx.response.empty(hyper::StatusCode::OK)),
},
(&Method::GET, GetVts(Some(vt_selection))) => {
let selection: Vec<String> = vt_selection.split(',').map(|x| x.to_string()).collect();
let selection: Vec<String> =
vt_selection.split(',').map(|x| x.to_string()).collect();

match &ctx.redis_cache {
Some(cache) => match cache.get_vts(Some(selection)).await {
Expand All @@ -427,4 +423,3 @@ where
})
}
}

19 changes: 10 additions & 9 deletions rust/openvasd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use redis_storage::{
CacheDispatcher, RedisCtx, VtHelper, FEEDUPDATE_SELECTOR, NOTUSUPDATE_SELECTOR,
};


pub mod config;
pub mod controller;
pub mod crypt;
Expand All @@ -22,7 +21,6 @@ pub mod scan;
pub mod storage;
pub mod tls;


fn create_context<DB>(
db: DB,
config: &config::Config,
Expand All @@ -48,19 +46,23 @@ fn create_context<DB>(
if let Some(redis) = config.redis_socket.redis_socket.to_str() {
let notus_cache: CacheDispatcher<RedisCtx, String>;
match CacheDispatcher::init(redis, NOTUSUPDATE_SELECTOR) {
Ok(c) => {notus_cache = c;},
Err(e) =>{
Ok(c) => {
notus_cache = c;
}
Err(e) => {
notus_cache = CacheDispatcher::default();
tracing::warn!("No notus cache found: {e}");
},
}
};
let vts_cache: CacheDispatcher<RedisCtx, String>;
match CacheDispatcher::init(redis, FEEDUPDATE_SELECTOR) {
Ok(c) => {vts_cache = c;},
Err(e) =>{
Ok(c) => {
vts_cache = c;
}
Err(e) => {
vts_cache = CacheDispatcher::default();
tracing::warn!("No vts cache found: {e}");
},
}
};
let cache = VtHelper::new(notus_cache, vts_cache);
ctx_builder = ctx_builder.redis_cache(ospcmd::GetVtsWrapper::new(cache));
Expand All @@ -76,7 +78,6 @@ fn create_context<DB>(
.build()
}


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let config = config::Config::load();
Expand Down
14 changes: 4 additions & 10 deletions rust/openvasd/src/ospcmd/getvts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ use std::marker::PhantomData;
use async_trait::async_trait;

use redis_storage::{RedisAddAdvisory, RedisAddNvt, RedisGetNvt, RedisWrapper, VtHelper};
use storage::{StorageError, item::Nvt};
use storage::{item::Nvt, StorageError};
use tokio::sync::RwLock;

#[async_trait]
pub trait GetVts {
async fn get_oids(&self) -> Result<Vec<String>, StorageError>;

async fn get_vts(&self, vt_selection: Option<Vec<String>>)
-> Result<Vec<Nvt>, StorageError>;
async fn get_vts(&self, vt_selection: Option<Vec<String>>) -> Result<Vec<Nvt>, StorageError>;
}

#[derive(Debug, Default)]
Expand All @@ -41,7 +40,6 @@ where
}
}


#[async_trait]
impl<R, K> GetVts for GetVtsWrapper<R, K>
where
Expand All @@ -52,11 +50,7 @@ where
self.vthelper.read().await.get_oids()
}

async fn get_vts(
&self,
vt_selection: Option<Vec<String>>,
) -> Result<Vec<Nvt>, StorageError> {

async fn get_vts(&self, vt_selection: Option<Vec<String>>) -> Result<Vec<Nvt>, StorageError> {
let oids: Vec<String>;
if let Some(selection) = vt_selection {
oids = selection;
Expand All @@ -70,7 +64,7 @@ where
match self.vthelper.read().await.retrieve_single_nvt(&oid)? {
Some(vt) => vt,
None => continue,
}
},
);
}
Ok(nvts)
Expand Down
4 changes: 2 additions & 2 deletions rust/openvasd/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ where
T: serde::de::DeserializeOwned,
H: hyper::body::Body,
<H as hyper::body::Body>::Error: std::error::Error,

{
let body = req.into_body();
let bytes = match body.collect().await {
Ok(x) => x.to_bytes(),
Err(e) => {
return Err(response.internal_server_error(&e));},
return Err(response.internal_server_error(&e));
}
};
match serde_json::from_slice(&bytes) {
Ok(json) => Ok(json),
Expand Down
2 changes: 1 addition & 1 deletion rust/openvasd/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Response {
#[inline]
pub async fn ok_json_stream<T, S>(&self, value: T) -> Result
where
T: Iterator<Item = S> + Send + 'static,
T: Iterator<Item = S> + Send + 'static,
S: Serialize + Clone + Send + std::fmt::Debug + 'static,
{
let value = value.map(|x| serde_json::to_vec(&x).unwrap());
Expand Down
3 changes: 1 addition & 2 deletions rust/openvasd/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ where
let certfile = fs::File::open(filename)
.map_err(|e| error(format!("failed to open {:?}: {}", filename, e)))?;
let mut reader = io::BufReader::new(certfile);
rustls_pemfile::certs(&mut reader)
.map(|x| x.into_iter().map(CertificateDer::from).collect())
rustls_pemfile::certs(&mut reader).map(|x| x.into_iter().map(CertificateDer::from).collect())
}

// Load private key from file.
Expand Down
14 changes: 9 additions & 5 deletions rust/redis-storage/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ pub trait RedisGetNvt: RedisWrapper {
let mut prefs_list = self.lrange(&keyname, 0, -1)?;
let mut prefs: Vec<NvtPreference> = Vec::new();
for p in prefs_list.iter_mut() {
if let Some(sp) = p.splitn(4, "|||").collect_tuple::<(&str, &str, &str, &str)>(){
if let Some(sp) = p
.splitn(4, "|||")
.collect_tuple::<(&str, &str, &str, &str)>()
{
prefs.push(NvtPreference::from(sp));
}
}
Expand All @@ -309,9 +312,11 @@ pub trait RedisGetNvt: RedisWrapper {
fn get_tags(tags: &str) -> BTreeMap<TagKey, TagValue> {
let mut tag_map = BTreeMap::new();

let tag_list = tags
.split('|')
.map(|x| x.splitn(2, '=').collect_tuple::<(&str, &str)>().unwrap_or_default());
let tag_list = tags.split('|').map(|x| {
x.splitn(2, '=')
.collect_tuple::<(&str, &str)>()
.unwrap_or_default()
});

for (k, v) in tag_list.into_iter() {
if let Ok(tk) = TagKey::from_str(k) {
Expand Down Expand Up @@ -630,7 +635,6 @@ where
self.vts.retrieve_nvt(oid)
}
}

}

/// Cache implementation.
Expand Down

0 comments on commit 8bc64f1

Please sign in to comment.