parsing SSK key

This commit is contained in:
Horhik 2021-01-26 19:50:13 +02:00
parent 1b55d4babd
commit 9da316c400
2 changed files with 49 additions and 8 deletions

View file

@ -4,6 +4,8 @@ version = "0.0.1"
authors = ["Horhik <horhik@tuta.io>"] authors = ["Horhik <horhik@tuta.io>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
regex = "1.4.3"

View file

@ -1,4 +1,5 @@
use super::types::*; use super::types::*;
use regex::Regex;
impl ClientHello { impl ClientHello {
fn new(name: String, exp_ver: f32) -> Self { fn new(name: String, exp_ver: f32) -> Self {
@ -103,12 +104,13 @@ impl FcpRequest for GenerateSSK {
} }
} }
#[derive(Debug, PartialEq)]
pub struct SSK { pub struct SSK {
sign_key: String, sign_key: String,
decrypt_key: String, decrypt_key: String,
settings: String, settings: Option<String>,
} }
#[derive(Debug, PartialEq)]
pub struct USK { pub struct USK {
ssk: SSK, ssk: SSK,
index: i32, index: i32,
@ -121,18 +123,55 @@ pub struct SSKKeypair {
} }
trait FcpParser<T> { trait FcpParser<T> {
fn parse(palin: String) -> T; fn parse(palin: &str) -> Option<T>;
} }
impl FcpParser<SSK> for SSK { impl FcpParser<SSK> for SSK {
fn parse(plain: String) -> SSK { fn parse(plain: &str) -> Option<SSK> {
SSK { let reg1 = Regex::new(r".*\w{3}@(.*),(.*),(.*)/?$?").unwrap();
sign_key: "DF".to_string(), let reg2 = Regex::new(r".*\w{3}@(.*),(.*)/$").unwrap();
decrypt_key: "dfs".to_string(), match reg1.captures(plain) {
settings: "DFS".to_string(), Some(reg) => Some(SSK {
sign_key: reg[1].to_string(),
decrypt_key: reg[2].to_string(),
settings: Some(reg[3].to_string()),
}),
None => match reg2.captures(plain) {
Some(reg) => Some(SSK {
sign_key: reg[1].to_string(),
decrypt_key: reg[2].to_string(),
settings: None,
}),
None => None,
},
} }
} }
} }
#[test]
fn is_ssk_parsing() {
// SSK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM/
// SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE
let ssk = SSK::parse("SSK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM/").unwrap();
let ssk2 = SSK::parse("SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE").unwrap();
assert_eq!(
ssk,
SSK {
sign_key: "AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr".to_string(),
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
settings: None
}
);
assert_eq!(
ssk2,
SSK {
sign_key: "BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0".to_string(),
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
settings: Some("AQABAAE".to_string()),
}
);
}
impl SSKKeypair { impl SSKKeypair {
/* /*
fn parse(plain: String) -> Self { fn parse(plain: String) -> Self {