[−][src]Enum iocutil::SampleHash
manage a hash value (sha256/sha1/md5)
Variants
Sha1(String)
Sha256(String)
Md5(String)
Methods
impl SampleHash
[src]
pub fn new(hash: impl AsRef<str>) -> Result<Self, Error>
[src]
new SampleHash from md5/sha1/sha256 string
pub fn map<T>(hashes: impl IntoIterator<Item = impl TryInto<SampleHash>>) -> T where
T: FromIterator<Result<SampleHash, Error>>,
[src]
T: FromIterator<Result<SampleHash, Error>>,
map strings to SampleHash
try_map
is a better way if you want to map to Result (like Result<Vec<_>, _>).
Example
use iocutil::prelude::*; let hashes = vec![ "d41d8cd98f00b204e9800998ecf8427e", "invalid_hash" ]; let r1: Result<Vec<_>, _> = SampleHash::map(&hashes); assert!(r1.is_err()); let r2: Vec<Result<_, _>> = SampleHash::map(&hashes); assert_eq!(r2.len(), 2); assert!(r2.iter().nth(0).unwrap().is_ok()); assert!(r2.iter().nth(1).unwrap().is_err());
pub fn try_map<T>(
hashes: impl IntoIterator<Item = impl TryInto<SampleHash>>
) -> Result<T, Error> where
T: FromIterator<SampleHash>,
[src]
hashes: impl IntoIterator<Item = impl TryInto<SampleHash>>
) -> Result<T, Error> where
T: FromIterator<SampleHash>,
try map strings to SampleHash
Example
use iocutil::prelude::*; use std::collections::HashSet; let hashes1 = vec![ "d41d8cd98f00b204e9800998ecf8427e", "d41d8cd98f00b204e9800998ecf8427e" ]; let r1: HashSet<_> = SampleHash::try_map(hashes1).expect("failed to map"); assert_eq!(r1.len(), 1); assert!(r1.contains(&sample!("d41d8cd98f00b204e9800998ecf8427e"))); let hashes2 = vec![ "d41d8cd98f00b204e9800998ecf8427e", "invalid_hash" ]; let r2: Result<HashSet<_>, _> = SampleHash::try_map(&hashes2); assert!(r2.is_err());
pub fn uniquify<T>(
hashes: impl IntoIterator<Item = impl TryInto<SampleHash>>
) -> T where
T: FromIterator<SampleHash>,
[src]
hashes: impl IntoIterator<Item = impl TryInto<SampleHash>>
) -> T where
T: FromIterator<SampleHash>,
uniquify the hashes
Example
use iocutil::prelude::*; let twice = vec![ "d41d8cd98f00b204e9800998ecf8427e", "da39a3ee5e6b4b0d3255bfef95601890afd80709", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", // uniquify case-insensitive "D41D8CD98F00B204E9800998ECF8427E", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", "a", // please note that invalid hashes are ignored ]; let uniqued: Vec<_> = SampleHash::uniquify(twice); assert_eq!(uniqued.len(), 3); assert!(uniqued.contains(&sample!("d41d8cd98f00b204e9800998ecf8427e"))); assert!(uniqued.contains(&sample!("da39a3ee5e6b4b0d3255bfef95601890afd80709"))); assert!(uniqued.contains(&sample!("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")));
pub fn find<T>(text: impl AsRef<str>) -> T where
T: FromIterator<SampleHash>,
[src]
T: FromIterator<SampleHash>,
find unique hashes in specified text
Example
use iocutil::prelude::*; let txt = r#"d41d8cd98f00b204e9800998ecf8427e,da39a3ee5e6b4b0d3255bfef95601890afd80709,e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 D41D8CD98F00B204E9800998ECF8427E,DA39A3EE5E6B4B0D3255BFEF95601890AFD80709,E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 "#; let hashes: Vec<_> = SampleHash::find(txt); // it scrapes unique hashes (ignore-case) assert_eq!(hashes.len(), 3);
pub fn scrape<T>(url: impl AsRef<str>) -> Result<T, Error> where
T: FromIterator<SampleHash>,
[src]
T: FromIterator<SampleHash>,
scrape hashes from specified url
Example
ⓘThis example is not tested
use iocutil::prelude::*; let hashes: std::collections::HashSet<_> = SampleHash::scrape("https://www.malware-traffic-analysis.net/2019/05/20/index.html").expect("failed to scrape https://www.malware-traffic-analysis.net/2019/05/20/index.html"); assert_eq!(hashes.len(), 2); assert!(hashes.contains(&sample!("7f335f990851510ab9654e9fc1add2acec2c38a64563b711031769c58ecd45c0"))); assert!(hashes.contains(&sample!("5a7042e698ce8e5cf6c4615e41a4205a52d9bb18a6ff214a967724c866cb72b4")));
Trait Implementations
impl AsRef<str> for SampleHash
[src]
impl Into<String> for SampleHash
[src]
impl Clone for SampleHash
[src]
fn clone(&self) -> SampleHash
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Eq for SampleHash
[src]
impl PartialEq<SampleHash> for SampleHash
[src]
fn eq(&self, other: &SampleHash) -> bool
[src]
fn ne(&self, other: &SampleHash) -> bool
[src]
impl Display for SampleHash
[src]
impl Debug for SampleHash
[src]
impl<'_> TryFrom<&'_ str> for SampleHash
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &str) -> Result<Self, Self::Error>
[src]
impl<'_, '_> TryFrom<&'_ &'_ str> for SampleHash
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &&str) -> Result<Self, Self::Error>
[src]
impl TryFrom<String> for SampleHash
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: String) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ String> for SampleHash
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: &String) -> Result<Self, Self::Error>
[src]
impl FromStr for SampleHash
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for SampleHash
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl StructuralPartialEq for SampleHash
[src]
impl StructuralEq for SampleHash
[src]
Auto Trait Implementations
impl Send for SampleHash
impl Sync for SampleHash
impl Unpin for SampleHash
impl UnwindSafe for SampleHash
impl RefUnwindSafe for SampleHash
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<'a, T> TryFrom<&'a str> for T where
T: FromStr,
T: FromStr,
type Err = <T as FromStr>::Err
fn try_from(string: &'a str) -> Result<T, <T as TryFrom<&'a str>>::Err>
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,