faker_rust/default/
vulnerability_identifier.rs1use crate::config::FakerConfig;
4
5pub fn cve() -> String {
7 let config = FakerConfig::current();
8 let year = config.rand_range(1999, 2026);
9 let number = config.rand_range(1, 100000);
10 format!("CVE-{}-{}", year, number)
11}
12
13pub fn cwe() -> String {
15 let config = FakerConfig::current();
16 let number = config.rand_range(1, 1000);
17 format!("CWE-{}", number)
18}
19
20pub fn ghsa() -> String {
22 let config = FakerConfig::current();
23 let chars: String = (0..4)
24 .map(|_| config.rand_char(&['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']))
25 .collect();
26 format!("GHSA-{}-{}", chars, config.rand_range(1000, 10000))
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_cve() {
35 let id = cve();
36 assert!(id.starts_with("CVE-"));
37 assert!(id.len() >= 10);
38 }
39
40 #[test]
41 fn test_cwe() {
42 let id = cwe();
43 assert!(id.starts_with("CWE-"));
44 }
45
46 #[test]
47 fn test_ghsa() {
48 let id = ghsa();
49 assert!(id.starts_with("GHSA-"));
50 }
51}