Add validate command line option
This commit is contained in:
parent
78b45cf929
commit
e001afdaed
3 changed files with 83 additions and 15 deletions
11
src/key.rs
11
src/key.rs
|
@ -2,17 +2,18 @@ use std::collections::VecDeque;
|
|||
|
||||
use openssl::bn::BigNum;
|
||||
|
||||
const P_CHARSET: [char; 24] = [
|
||||
use crate::PK_LENGTH;
|
||||
|
||||
/// The allowed character set in a product key.
|
||||
pub const P_KEY_CHARSET: [char; 24] = [
|
||||
'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y', '2', '3',
|
||||
'4', '6', '7', '8', '9',
|
||||
];
|
||||
|
||||
const PK_LENGTH: usize = 25;
|
||||
|
||||
pub fn base24_decode(cd_key: &str) -> Vec<u8> {
|
||||
let p_decoded_key: Vec<u8> = cd_key
|
||||
.chars()
|
||||
.filter_map(|c| P_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
|
||||
.filter_map(|c| P_KEY_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
|
||||
.collect();
|
||||
|
||||
let mut y = BigNum::from_u32(0).unwrap();
|
||||
|
@ -28,7 +29,7 @@ pub fn base24_decode(cd_key: &str) -> Vec<u8> {
|
|||
pub fn base24_encode(byte_seq: &[u8]) -> String {
|
||||
let mut z = BigNum::from_slice(byte_seq).unwrap();
|
||||
let mut out: VecDeque<char> = VecDeque::new();
|
||||
(0..=24).for_each(|_| out.push_front(P_CHARSET[z.div_word(24).unwrap() as usize]));
|
||||
(0..=24).for_each(|_| out.push_front(P_KEY_CHARSET[z.div_word(24).unwrap() as usize]));
|
||||
out.iter().collect()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue