Skip to content

Commit

Permalink
Format code using 'cargo fmt'
Browse files Browse the repository at this point in the history
  • Loading branch information
Atul9 committed Jun 21, 2020
1 parent da0e6aa commit c18e137
Show file tree
Hide file tree
Showing 128 changed files with 3,683 additions and 2,734 deletions.
9 changes: 4 additions & 5 deletions examples/boxxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[macro_use] extern crate boxxy;
extern crate sn0int;
#[macro_use]
extern crate boxxy;
extern crate env_logger;
extern crate sn0int;

fn stage1(sh: &mut boxxy::Shell, _args: Vec<String>) -> Result<(), boxxy::Error> {
shprintln!(sh, "[*] starting stage1");
Expand All @@ -14,8 +15,6 @@ fn main() {

println!("stage1 activate sandbox");

let toolbox = boxxy::Toolbox::new().with(vec![
("stage1", stage1),
]);
let toolbox = boxxy::Toolbox::new().with(vec![("stage1", stage1)]);
boxxy::Shell::new(toolbox).run()
}
5 changes: 2 additions & 3 deletions examples/maxmind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub enum Args {
#[structopt(name="asn")]
#[structopt(name = "asn")]
Asn(AsnArgs),
#[structopt(name="geoip")]
#[structopt(name = "geoip")]
GeoIP(GeoIPArgs),
}

Expand Down Expand Up @@ -47,7 +47,6 @@ impl GeoIPArgs {
}
}


fn run() -> Result<()> {
let args = Args::from_args();
debug!("{:?}", args);
Expand Down
12 changes: 5 additions & 7 deletions examples/spinners.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use sn0int::term::{Spinner, StackedSpinners, SPINNERS};
use std::thread;
use std::time::Duration;
use sn0int::term::{SPINNERS, Spinner, StackedSpinners};
use structopt::StructOpt;


#[derive(Debug, StructOpt)]
pub enum Args {
#[structopt(name="single")]
#[structopt(name = "single")]
Single(Single),
#[structopt(name="stacked")]
#[structopt(name = "stacked")]
Stacked(Stacked),
}

#[derive(Debug, StructOpt)]
pub struct Single {
idx: usize,
#[structopt(long="ticks", default_value="100")]
#[structopt(long = "ticks", default_value = "100")]
ticks: usize,
}

Expand All @@ -33,8 +32,7 @@ impl Single {
}

#[derive(Debug, StructOpt)]
pub struct Stacked {
}
pub struct Stacked {}

impl Stacked {
fn run(&self) {
Expand Down
39 changes: 21 additions & 18 deletions sn0int-common/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::errors::*;
use nom;
use serde::{de, Serialize, Serializer, Deserialize, Deserializer};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::result;
use std::str::FromStr;


#[inline(always)]
fn valid_char(c: char) -> bool {
nom::character::is_alphanumeric(c as u8) || c == '-'
Expand All @@ -20,15 +19,15 @@ pub fn valid_name(name: &str) -> Result<()> {
}

fn module(s: &str) -> nom::IResult<&str, ModuleID> {
let (input, (author, _, name)) = nom::sequence::tuple((
token,
nom::bytes::complete::tag("/"),
token,
))(s)?;
Ok((input, ModuleID {
author: author.to_string(),
name: name.to_string(),
}))
let (input, (author, _, name)) =
nom::sequence::tuple((token, nom::bytes::complete::tag("/"), token))(s)?;
Ok((
input,
ModuleID {
author: author.to_string(),
name: name.to_string(),
},
))
}

#[inline]
Expand All @@ -52,8 +51,8 @@ impl FromStr for ModuleID {
type Err = Error;

fn from_str(s: &str) -> Result<ModuleID> {
let (trailing, module) = module(s)
.map_err(|err| format_err!("Failed to parse module id: {:?}", err))?;
let (trailing, module) =
module(s).map_err(|err| format_err!("Failed to parse module id: {:?}", err))?;
if !trailing.is_empty() {
bail!("Trailing data in module id");
}
Expand All @@ -72,7 +71,8 @@ impl Serialize for ModuleID {

impl<'de> Deserialize<'de> for ModuleID {
fn deserialize<D>(deserializer: D) -> result::Result<Self, D::Error>
where D: Deserializer<'de>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
FromStr::from_str(&s).map_err(de::Error::custom)
Expand All @@ -86,10 +86,13 @@ mod tests {
#[test]
fn verify_valid() {
let result = ModuleID::from_str("kpcyrd/foo").expect("parse");
assert_eq!(result, ModuleID {
author: "kpcyrd".to_string(),
name: "foo".to_string(),
});
assert_eq!(
result,
ModuleID {
author: "kpcyrd".to_string(),
name: "foo".to_string(),
}
);
}

#[test]
Expand Down
11 changes: 7 additions & 4 deletions sn0int-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate failure;
#[macro_use] extern crate nom;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate nom;

pub mod api;
pub mod errors;
pub use crate::errors::*;
pub mod metadata;
pub mod id;
pub mod metadata;
pub use crate::id::*;

pub use rocket_failure_errors::StrictApiResponse as ApiResponse;
Expand Down
80 changes: 49 additions & 31 deletions sn0int-common/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::errors::*;

use std::str::FromStr;


#[derive(Debug, PartialEq, Clone)]
pub enum EntryType {
Description,
Expand Down Expand Up @@ -143,8 +142,7 @@ impl FromStr for Metadata {
type Err = Error;

fn from_str(code: &str) -> Result<Metadata> {
let (_, lines) = metalines(code)
.map_err(|_| format_err!("Failed to parse header"))?;
let (_, lines) = metalines(code).map_err(|_| format_err!("Failed to parse header"))?;

let mut data = NewMetadata::default();

Expand Down Expand Up @@ -173,16 +171,20 @@ pub struct NewMetadata<'a> {

impl<'a> NewMetadata<'a> {
fn try_from(self) -> Result<Metadata> {
let description = self.description.ok_or_else(|| format_err!("Description is required"))?;
let version = self.version.ok_or_else(|| format_err!("Version is required"))?;
let description = self
.description
.ok_or_else(|| format_err!("Description is required"))?;
let version = self
.version
.ok_or_else(|| format_err!("Version is required"))?;
let source = match self.source {
Some(x) => Some(x.parse()?),
_ => None,
};
let keyring_access = self.keyring_access.into_iter()
.map(String::from)
.collect();
let license = self.license.ok_or_else(|| format_err!("License is required"))?;
let keyring_access = self.keyring_access.into_iter().map(String::from).collect();
let license = self
.license
.ok_or_else(|| format_err!("License is required"))?;
let license = license.parse()?;

Ok(Metadata {
Expand Down Expand Up @@ -219,55 +221,71 @@ mod tests {

#[test]
fn verify_simple() {
let metadata = Metadata::from_str(r#"-- Description: Hello world, this is my description
let metadata = Metadata::from_str(
r#"-- Description: Hello world, this is my description
-- Version: 1.0.0
-- Source: domains
-- License: WTFPL
"#).expect("parse");
assert_eq!(metadata, Metadata {
description: "Hello world, this is my description".to_string(),
version: "1.0.0".to_string(),
license: License::WTFPL,
source: Some(Source::Domains),
keyring_access: Vec::new(),
});
"#,
)
.expect("parse");
assert_eq!(
metadata,
Metadata {
description: "Hello world, this is my description".to_string(),
version: "1.0.0".to_string(),
license: License::WTFPL,
source: Some(Source::Domains),
keyring_access: Vec::new(),
}
);
}

#[test]
fn verify_no_source() {
let metadata = Metadata::from_str(r#"-- Description: Hello world, this is my description
let metadata = Metadata::from_str(
r#"-- Description: Hello world, this is my description
-- Version: 1.0.0
-- License: WTFPL
"#).expect("parse");
assert_eq!(metadata, Metadata {
description: "Hello world, this is my description".to_string(),
version: "1.0.0".to_string(),
license: License::WTFPL,
source: None,
keyring_access: Vec::new(),
});
"#,
)
.expect("parse");
assert_eq!(
metadata,
Metadata {
description: "Hello world, this is my description".to_string(),
version: "1.0.0".to_string(),
license: License::WTFPL,
source: None,
keyring_access: Vec::new(),
}
);
}

#[test]
fn verify_require_license() {
let metadata = Metadata::from_str(r#"-- Description: Hello world, this is my description
let metadata = Metadata::from_str(
r#"-- Description: Hello world, this is my description
-- Version: 1.0.0
-- Source: domains
"#);
"#,
);
assert!(metadata.is_err());
}

#[test]
fn verify_require_opensource_license() {
let metadata = Metadata::from_str(r#"-- Description: Hello world, this is my description
let metadata = Metadata::from_str(
r#"-- Description: Hello world, this is my description
-- Version: 1.0.0
-- Source: domains
-- License: Proprietary
"#);
"#,
);
assert!(metadata.is_err());
}

Expand Down
Loading

0 comments on commit c18e137

Please sign in to comment.