Skip to content

Commit

Permalink
Change: serde optional behind feature toggle
Browse files Browse the repository at this point in the history
To allow multiple serializer the serde macro usage is behing a feature
toggle. This allows to use models without serde support and with that
the possibility to write own serializer and work with the same data
structure.

The feature toggle is `serde_support` and is enabled on default.

Additionally the json module is dropped as it is not limited to json.
  • Loading branch information
nichtsfrei committed May 3, 2023
1 parent 0d68b80 commit ece68df
Show file tree
Hide file tree
Showing 22 changed files with 464 additions and 356 deletions.
10 changes: 9 additions & 1 deletion rust/models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ license = "GPL-2.0-or-later"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = {version = "1", features = ["derive"]}
serde = {version = "1", features = ["derive"], optional = true}
#serde_json = "1"


[features]
default = ["serde_support"]
serde_support = ["serde"]

[dev-dependencies]
serde_json = "1"
Original file line number Diff line number Diff line change
@@ -1,57 +1,67 @@
use serde::{Deserialize, Serialize};

/// Represents a set of credentials to be used for scanning to access a host.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct Credential {
/// Service to use for accessing a host
pub service: Service,
/// Port used for getting access. If missing a standard port is used
pub port: Option<u16>,
#[serde(flatten)]
#[cfg_attr(feature = "serde_support", serde(flatten))]
/// Type of the credential to get access. Different services support different types.
pub credential_type: CredentialType,
}

/// Enum of available services
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum Service {
#[serde(rename = "ssh")]
#[cfg_attr(feature = "serde_support", serde(rename = "ssh"))]
/// SSH, supports [UP](CredentialType::UP) and [USK](CredentialType::USK) as credential types
SSH,
#[serde(rename = "smb")]
#[cfg_attr(feature = "serde_support", serde(rename = "smb"))]
/// SMB, supports [UP](CredentialType::UP)
SMB,
#[serde(rename = "esxi")]
#[cfg_attr(feature = "serde_support", serde(rename = "esxi"))]
/// ESXi, supports [UP](CredentialType::UP)
ESXi,
#[serde(rename = "snmp")]
#[cfg_attr(feature = "serde_support", serde(rename = "snmp"))]
/// SNMP, supports [SNMP](CredentialType::SNMP)
SNMP,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
/// Enum representing the type of credentials.
pub enum CredentialType {
#[serde(rename = "up")]
#[cfg_attr(feature = "serde_support", serde(rename = "up"))]
/// User/password credentials.
UP {
/// The username for authentication.
username: String,
/// The password for authentication.
password: String,
},
#[serde(rename = "usk")]
#[cfg_attr(feature = "serde_support", serde(rename = "usk"))]
/// User/ssh-key credentials.
USK {
/// The username for authentication.
username: String,
/// The password for authentication.
password: String,
#[serde(rename = "private")]
#[cfg_attr(feature = "serde_support", serde(rename = "private"))]
/// The private key for authentication.
private_key: String,
},
#[serde(rename = "snmp")]
#[cfg_attr(feature = "serde_support", serde(rename = "snmp"))]
/// SNMP credentials.
SNMP {
/// The SNMP username.
Expand Down
15 changes: 10 additions & 5 deletions rust/models/src/json/host_info.rs → rust/models/src/host_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use serde::{Deserialize, Serialize};

/// Information about hosts of a running scan
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct HostInfo {
/// Number of all hosts, that are contained in a target
pub all: i32,
Expand All @@ -15,7 +17,10 @@ pub struct HostInfo {
pub queued: i32,
/// Number of hosts, that are already finished scanning
pub finished: i32,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(
feature = "serde_support",
serde(skip_serializing_if = "Vec::is_empty")
)]
/// IPs of hosts, that are currently scanned.
pub scanning: Option<Vec<String>>,
pub scanning: Vec<String>,
}
153 changes: 0 additions & 153 deletions rust/models/src/json/mod.rs

This file was deleted.

21 changes: 0 additions & 21 deletions rust/models/src/json/port.rs

This file was deleted.

51 changes: 0 additions & 51 deletions rust/models/src/json/result.rs

This file was deleted.

18 changes: 0 additions & 18 deletions rust/models/src/json/scan.rs

This file was deleted.

18 changes: 0 additions & 18 deletions rust/models/src/json/scan_action.rs

This file was deleted.

Loading

0 comments on commit ece68df

Please sign in to comment.