add AllData response parser

This commit is contained in:
Horhik 2021-04-23 09:45:54 +03:00
parent 734c733e50
commit 64f8838008
3 changed files with 102 additions and 4 deletions

View file

@ -279,7 +279,7 @@ impl SSKKeypair {
} }
pub struct ClientPut { pub struct ClientPut {
uri: SSK, //TODO create key type uri: USK, //TODO create key type
data_length: usize, data_length: usize,
filename: Option<String>, filename: Option<String>,
content_type: Option<String>, content_type: Option<String>,
@ -409,7 +409,7 @@ impl FcpRequest for ClientPut {
} }
impl ClientPut { impl ClientPut {
pub fn new_default_direct(uri: SSK, identifier: &str, data: &str) -> ClientPut { pub fn new_default_direct(uri: USK, identifier: &str, data: &str) -> ClientPut {
ClientPut { ClientPut {
uri: uri, uri: uri,
data_length: data.len(), data_length: data.len(),
@ -456,10 +456,14 @@ fn is_client_put_converting() {
EndMessage\n\ EndMessage\n\
Hey jude\n"; Hey jude\n";
let input = ClientPut::new_default_direct( let input = ClientPut::new_default_direct(
SSK { USK{
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()),
},
path: "myidentifier".to_string()
}, },
"myidentifier", "myidentifier",
"Hey jude", "Hey jude",

94
src/node/fcp_response.rs Normal file
View file

@ -0,0 +1,94 @@
use crate::types::traits::FcpParser;
use regex::Regex;
use std::str::FromStr;
/*
AllData
Identifier=Request Number One
DataLength=37261 // length of data
StartupTime=1189683889
CompletionTime=1189683889
Metadata.ContentType=text/plain;charset=utf-8
Data
<37261 bytes of data>
AllData\n
Identifier=get1\n
CompletionTime=1619156374827\n
StartupTime=1619156374743\n
DataLength=33\n
Global=false\n
Metadata.ContentType=application/octet-stream\n
Data\n
hello\n Yeah kek ruururun\n\n\nKE^[u
*/
#[derive(Debug, PartialEq)]
pub struct AllData {
pub identifier: String,
pub startup_time: String,
pub completion_time: String,
pub data_length: usize,
pub global: bool,
pub metadata_content_type: String,
pub data: String,
}
impl FcpParser<AllData> for AllData {
fn parse(plain: &str) -> Option<AllData> {
let reg = Regex::new(
r"^AllData\nIdentifier=(.*)\nCompletionTime=(.*)\nStartupTime=(.*)\nDataLength=(.*)\nGlobal=(.*)\nMetadata\.ContentType=(.*)\nData\n((\n?.*)*)"
)
.unwrap();
println!("{:?}", reg);
let res = reg.captures(plain).unwrap();
let identifier = res[1].to_string();
// let completion_time = u32::from_str_radix(&res[2], 10).unwrap();
// let startup_time = u32::from_str_radix(&res[3], 10).unwrap();
let completion_time = res[2].to_string();
let startup_time = res[3].to_string();
let data_length = usize::from_str_radix(&res[4], 10).unwrap();
let global = bool::from_str(&res[5]).unwrap();
let metadata = res[6].to_string();
let data = res[7].to_string();
return Some(AllData {
identifier: identifier,
startup_time: startup_time,
completion_time: completion_time,
data_length: data_length,
global: global,
metadata_content_type: metadata,
data: data,
});
}
}
#[test]
fn is_all_data_parsing() {
assert_eq!(
AllData::parse(
"AllData\n\
Identifier=get1\n\
CompletionTime=1619156374827\n\
StartupTime=1619156374743\n\
DataLength=33\n\
Global=false\n\
Metadata.ContentType=application/octet-stream\n\
Data\n\
hello\n Yeah kek ruururun\n\n\nKE",
)
.unwrap(),
AllData {
identifier: "get1".to_string(),
startup_time: "1619156374743".to_string(),
completion_time: "1619156374827".to_string(),
data_length: 33,
global: false,
metadata_content_type: "application/octet-stream".to_string(),
data:"hello\n Yeah kek ruururun\n\n\nKE".to_string()
}
)
}

View file

@ -1 +1 @@
pub mod fcp_response;