add usk parsing function
This commit is contained in:
parent
e908674813
commit
d65a0bb4cf
|
@ -1,6 +1,6 @@
|
||||||
use super::types::*;
|
use super::types::*;
|
||||||
use crate::types::traits::*;
|
use crate::types::traits::*;
|
||||||
use crate::types::{SSKKeypair, SSK, ReturnType};
|
use crate::types::{ReturnType, SSKKeypair, SSK, USK};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
impl ClientHello {
|
impl ClientHello {
|
||||||
|
@ -187,7 +187,9 @@ fn is_ssk_parsing() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// TODO Create just Key type which contains from sign_key, decrtypt_key, settings and path.
|
||||||
|
// And use it for all keys, like SSK, USK e.t.c.
|
||||||
|
/// converting SSK key to string
|
||||||
impl FcpRequest for SSK {
|
impl FcpRequest for SSK {
|
||||||
fn convert(&self) -> String {
|
fn convert(&self) -> String {
|
||||||
let mut settings: String = "".to_string();
|
let mut settings: String = "".to_string();
|
||||||
|
@ -212,6 +214,45 @@ fn is_ssk_converting() {
|
||||||
settings: Some("AQABAAE".to_string()),
|
settings: Some("AQABAAE".to_string()),
|
||||||
}.convert(), "SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE")
|
}.convert(), "SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE")
|
||||||
}
|
}
|
||||||
|
/// converting USK key to string
|
||||||
|
impl FcpRequest for USK {
|
||||||
|
fn convert(&self) -> String {
|
||||||
|
let mut settings: String = "".to_string();
|
||||||
|
//There's no might be settings for key, and we skipping it
|
||||||
|
match &self.ssk.settings {
|
||||||
|
Some(res) => settings = format!(",{}", res),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
format!(
|
||||||
|
"USK@{},{}{}/{}",
|
||||||
|
self.ssk.sign_key, self.ssk.decrypt_key, settings, self.path
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_usk_converting() {
|
||||||
|
assert_eq!(
|
||||||
|
USK {
|
||||||
|
ssk: SSK {
|
||||||
|
sign_key: "AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr".to_string(),
|
||||||
|
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
||||||
|
settings: None
|
||||||
|
},
|
||||||
|
path: "messages/0".to_string()
|
||||||
|
}
|
||||||
|
.convert(), "USK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM/messages/0");
|
||||||
|
assert_eq!(
|
||||||
|
USK{ ssk:
|
||||||
|
SSK {
|
||||||
|
sign_key: "BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0".to_string(),
|
||||||
|
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
||||||
|
settings: Some("AQABAAE".to_string()),
|
||||||
|
},
|
||||||
|
path: "messages/0".to_string()
|
||||||
|
}
|
||||||
|
.convert(), "USK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE/messages/0")
|
||||||
|
}
|
||||||
|
|
||||||
impl SSKKeypair {
|
impl SSKKeypair {
|
||||||
/*
|
/*
|
||||||
|
@ -395,20 +436,18 @@ fn is_client_put_converting() {
|
||||||
let fin = "ClientPut\n\
|
let fin = "ClientPut\n\
|
||||||
URI=SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE\n\
|
URI=SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE\n\
|
||||||
DataLength=8\n\
|
DataLength=8\n\
|
||||||
Filename=thefile\n\
|
|
||||||
ContentType=text/json\n\
|
ContentType=text/json\n\
|
||||||
Identifier=myidentifier\n\
|
Identifier=myidentifier\n\
|
||||||
Verbosity=0\n\
|
Verbosity=0\n\
|
||||||
MaxRetries=50\n\
|
MaxRetries=50\n\
|
||||||
EndMessage\n\
|
EndMessage\n\
|
||||||
Hey jude\n";
|
Hey jude\n";
|
||||||
let input = ClientPut::new_default(
|
let input = ClientPut::new_default_direct(
|
||||||
SSK {
|
SSK {
|
||||||
sign_key: "BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0".to_string(),
|
sign_key: "BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0".to_string(),
|
||||||
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
||||||
settings: Some("AQABAAE".to_string()),
|
settings: Some("AQABAAE".to_string()),
|
||||||
},
|
},
|
||||||
"thefile",
|
|
||||||
"myidentifier",
|
"myidentifier",
|
||||||
"Hey jude",
|
"Hey jude",
|
||||||
);
|
);
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl<'de> Deserialize<'de> for SSK {
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
return Ok(SSK{sign_key: "lol".to_string(), decrypt_key: "kik".to_string(),settings: Some("kek".to_string())});
|
//return Ok(SSK{sign_key: "lol".to_string(), decrypt_key: "kik".to_string(),settings: Some("kek".to_string())});
|
||||||
match SSK::parse(v) {
|
match SSK::parse(v) {
|
||||||
Some(ssk) => {
|
Some(ssk) => {
|
||||||
Ok(ssk)
|
Ok(ssk)
|
||||||
|
@ -76,7 +76,7 @@ impl<'de> Deserialize<'de> for SSK {
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
return Ok(SSK{sign_key: "lol".to_string(), decrypt_key: "kik".to_string(),settings: Some("kek".to_string())});
|
//return Ok(SSK{sign_key: "lol".to_string(), decrypt_key: "kik".to_string(),settings: Some("kek".to_string())});
|
||||||
match SSK::parse(v) {
|
match SSK::parse(v) {
|
||||||
Some(ssk) => {
|
Some(ssk) => {
|
||||||
Ok(ssk)
|
Ok(ssk)
|
||||||
|
@ -110,7 +110,7 @@ impl<'de> Deserialize<'de> for SSK {
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct USK {
|
pub struct USK {
|
||||||
pub ssk: SSK,
|
pub ssk: SSK,
|
||||||
pub index: i32,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -138,8 +138,7 @@ mod tests {
|
||||||
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
||||||
settings: None,
|
settings: None,
|
||||||
};
|
};
|
||||||
let res = serde_json::from_str::<SSK>("SSK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM");
|
let res: SSK = serde_json::from_str("SSK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM").unwrap();
|
||||||
let aa = res.unwrap();
|
assert_eq!(res, ssk)
|
||||||
assert_eq!(aa, ssk)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue