@@ -19,6 +19,31 @@ use rand::Rng;
19
19
20
20
//Public Functions
21
21
22
+ /// Generates a valid product key
23
+ ///
24
+ /// # Example
25
+ ///
26
+ /// ```
27
+ /// use keyforge95::generate_product_key;
28
+ /// for _ in 0..10 {
29
+ /// let product_key: String = generate_product_key("retail"); // Both, "retail" and "oem" are available
30
+ /// assert_eq!(product_key.len(), 11);
31
+ /// assert_eq!(product_key.chars().nth(3).unwrap(), '-');
32
+ /// }
33
+ /// ```
34
+ #[ must_use]
35
+ pub fn generate_product_key ( key_type : & str ) -> String {
36
+ match key_type {
37
+ "retail" => {
38
+ // Use generate_block() for product key generation and print it with the right format
39
+ format ! ( "{}-{}" , generate_block( "a" ) , generate_block( "b" ) )
40
+ }
41
+ _ => {
42
+ panic ! ( "Invalid choice: {key_type}. Only 'retail' or 'oem' allowed." ) ;
43
+ }
44
+ }
45
+ }
46
+
22
47
/// Tests if a product key is valid
23
48
///
24
49
/// # Examples
@@ -76,31 +101,6 @@ pub fn validate_product_key(product_key: &str) -> bool {
76
101
}
77
102
}
78
103
79
- /// Generates a valid product key
80
- ///
81
- /// # Example
82
- ///
83
- /// ```
84
- /// use keyforge95::generate_product_key;
85
- /// for _ in 0..10 {
86
- /// let product_key: String = generate_product_key("retail"); // Both, "retail" and "oem" are available
87
- /// assert_eq!(product_key.len(), 11);
88
- /// assert_eq!(product_key.chars().nth(3).unwrap(), '-');
89
- /// }
90
- /// ```
91
- #[ must_use]
92
- pub fn generate_product_key ( key_type : & str ) -> String {
93
- match key_type {
94
- "retail" => {
95
- // Use generate_block() for product key generation and print it with the right format
96
- format ! ( "{}-{}" , generate_block( "a" ) , generate_block( "b" ) )
97
- }
98
- _ => {
99
- panic ! ( "Invalid choice: {key_type}. Only 'retail' or 'oem' allowed." ) ;
100
- }
101
- }
102
- }
103
-
104
104
// Functions
105
105
106
106
fn generate_block ( choice : & str ) -> String {
0 commit comments