add usk parsing function
This commit is contained in:
parent
e908674813
commit
d65a0bb4cf
|
@ -1,6 +1,6 @@
|
|||
use super::types::*;
|
||||
use crate::types::traits::*;
|
||||
use crate::types::{SSKKeypair, SSK, ReturnType};
|
||||
use crate::types::{ReturnType, SSKKeypair, SSK, USK};
|
||||
use regex::Regex;
|
||||
|
||||
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 {
|
||||
fn convert(&self) -> String {
|
||||
let mut settings: String = "".to_string();
|
||||
|
@ -212,6 +214,45 @@ fn is_ssk_converting() {
|
|||
settings: Some("AQABAAE".to_string()),
|
||||
}.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 {
|
||||
/*
|
||||
|
@ -355,7 +396,7 @@ impl FcpRequest for ClientPut {
|
|||
}
|
||||
|
||||
impl ClientPut {
|
||||
pub fn new_default_direct(uri: SSK, identifier: &str, data: &str) -> ClientPut {
|
||||
pub fn new_default_direct(uri: SSK, identifier: &str, data: &str) -> ClientPut {
|
||||
ClientPut {
|
||||
uri: uri,
|
||||
data_length: data.len(),
|
||||
|
@ -395,20 +436,18 @@ fn is_client_put_converting() {
|
|||
let fin = "ClientPut\n\
|
||||
URI=SSK@BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM,AQABAAE\n\
|
||||
DataLength=8\n\
|
||||
Filename=thefile\n\
|
||||
ContentType=text/json\n\
|
||||
Identifier=myidentifier\n\
|
||||
Verbosity=0\n\
|
||||
MaxRetries=50\n\
|
||||
EndMessage\n\
|
||||
Hey jude\n";
|
||||
let input = ClientPut::new_default(
|
||||
let input = ClientPut::new_default_direct(
|
||||
SSK {
|
||||
sign_key: "BnHXXv3Fa43w~~iz1tNUd~cj4OpUuDjVouOWZ5XlpX0".to_string(),
|
||||
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
||||
settings: Some("AQABAAE".to_string()),
|
||||
},
|
||||
"thefile",
|
||||
"myidentifier",
|
||||
"Hey jude",
|
||||
);
|
||||
|
|
|
@ -61,7 +61,7 @@ impl<'de> Deserialize<'de> for SSK {
|
|||
where
|
||||
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) {
|
||||
Some(ssk) => {
|
||||
Ok(ssk)
|
||||
|
@ -76,7 +76,7 @@ impl<'de> Deserialize<'de> for SSK {
|
|||
where
|
||||
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) {
|
||||
Some(ssk) => {
|
||||
Ok(ssk)
|
||||
|
@ -110,7 +110,7 @@ impl<'de> Deserialize<'de> for SSK {
|
|||
#[derive(Debug, PartialEq)]
|
||||
pub struct USK {
|
||||
pub ssk: SSK,
|
||||
pub index: i32,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -138,8 +138,7 @@ mod tests {
|
|||
decrypt_key: "AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM".to_string(),
|
||||
settings: None,
|
||||
};
|
||||
let res = serde_json::from_str::<SSK>("SSK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM");
|
||||
let aa = res.unwrap();
|
||||
assert_eq!(aa, ssk)
|
||||
let res: SSK = serde_json::from_str("SSK@AKTTKG6YwjrHzWo67laRcoPqibyiTdyYufjVg54fBlWr,AwUSJG5ZS-FDZTqnt6skTzhxQe08T-fbKXj8aEHZsXM").unwrap();
|
||||
assert_eq!(res, ssk)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue