hash_data/
lib.rs

1#![deny(missing_docs)]
2
3//! A library and command line tool for identifying hashes.
4//!
5//! The main part of this crate is in the build script (`build.rs`). The build script uses the TOML
6//! files in `data/` to generate a list of regexes with their matching hash types and uses the
7//! fixtures to generate tests.
8//!
9//! The TOML files found in data are language agnostic and can be used to build similar libraries
10//! in other languages.
11//!
12//! # Examples
13//!
14//! Using the library:
15//!
16//! ```
17//! assert_eq!(hash_data::parse("$1$42bad211$ums.eDtzK/1711rUkRsd31"), vec!["MD5(Unix)"])
18//! ```
19//!
20//! On the command line:
21//!
22//! ```sh
23//! $ hash-data '$1$42bad211$ums.eDtzK/1711rUkRsd31'
24//! MD5(Unix)
25//! ```
26//!
27//! # Supported hash types:
28//!
29//! - Adler32
30//! - Base64
31//! - Blowfish
32//!     - Eggdrop
33//!     - OpenBSD
34//! - CRC
35//!     - CRC-16, CRC-16-CCITT
36//!     - CRC-32
37//!     - CRC-32B
38//!     - CRC-96(ZIP)
39//! - DES
40//!     - Oracle
41//!     - Unix
42//! - Domain Cached Credentials
43//!     - Domain Cached Credentials 2
44//! - FCS
45//!     - FCS-16
46//!     - FCS-32
47//! - FNV
48//!     - FNV-132
49//!     - FNV-164
50//! - GHash
51//!     - GHash-32-3
52//!     - GHash-32-5
53//! - GOST R 34.11-94
54//! - Haval
55//!     - Haval-128
56//!     - Haval-160
57//!     - Haval-192
58//!     - Haval-224
59//!     - Haval-256
60//! - Joaat
61//! - Keccak
62//!     - Keccak-224
63//!     - Keccak-256
64//! - LM
65//! - Lineage II C4
66//! - Lotus Domino
67//! - MD2
68//! - MD4
69//! - MD5
70//!     - APR
71//!     - Cisco PIX
72//!     - IP.Board
73//!     - Joomla
74//!     - MyBB
75//!     - Palshop
76//!     - Unix
77//!     - Wordpress
78//!     - osCommerce
79//!     - phpBB3
80//! - MSSQL
81//!     - MSSQL(2000)
82//!     - MSSQL(2005)
83//!     - MSSQL(2008)
84//! - MySQL
85//!     - MySQL3.x
86//!     - MySQL4.x
87//!     - MySQL5.x
88//! - NTLM
89//! - RAdminv2.x
90//! - RIPEMD
91//!     - RIPEMD-128
92//!     - RIPEMD-160
93//!     - RIPEMD-256
94//!     - RIPEMD-320
95//! - SAM(LM_Hash:NT_Hash)
96//! - SHA
97//!     - SHA-1(Django)
98//!     - SHA-1(MaNGOS)
99//!     - SHA-1(MaNGOS2)
100//!     - SHA-224
101//!     - SHA-256
102//!     - SHA-256(Django)
103//!     - SHA-256(Unix)
104//!     - SHA-384
105//!     - SHA-384(Django)
106//!     - SHA-512
107//!     - SHA-512(Drupal)
108//!     - SHA-512(Unix)
109//!     - SHA3-384
110//!     - SHA3-512
111//! - SSHA-1
112//! - Skein
113//!     - Skein-256(128, 160, 224)
114//!     - Skein-512(128, 160, 224, 256, 384)
115//!     - Skein-1024(384, 512)
116//! - Snefru
117//!   - Snefru-128
118//!   - Snefru-256
119//! - Tiger
120//!   - Tiger-128
121//!   - Tiger-160
122//!   - Tiger-192
123//! - VNC
124//! - Whirlpool
125//! - XOR-32
126
127include!(concat!(env!("OUT_DIR"), "/regexes.rs"));
128
129use regexes::REGEXES;
130
131/// Parses the hash and returns potential hash types.
132///
133/// ```
134/// assert_eq!(hash_data::parse("$1$42bad211$ums.eDtzK/1711rUkRsd31"), vec!["MD5(Unix)"])
135/// ```
136pub fn parse(input: &str) -> Vec<&str> {
137    let mut matches = Vec::new();
138
139    if input.is_empty() {
140        return matches;
141    }
142
143    matches = REGEXES.iter().fold(matches, |mut a, (r, v)| {
144        if r.is_match(&input) {
145            a.append(&mut v.clone());
146        };
147        a
148    });
149    matches.sort();
150    matches
151}
152
153include!(concat!(env!("OUT_DIR"), "/fixture_tests.rs"));
154
155#[cfg(test)]
156mod tests {
157    use super::*;
158
159    #[test]
160    fn test_empty_input() {
161        assert_eq!(parse(&""), vec![] as Vec<&str>)
162    }
163
164    #[test]
165    fn test_no_match() {
166        assert_eq!(parse(&"not a matching hash"), vec![] as Vec<&str>)
167    }
168}