feat: add gcm semantic to b2p and p2b
This commit is contained in:
parent
28a8753d55
commit
8db0bbaa63
9 changed files with 299 additions and 206 deletions
|
|
@ -1,15 +1,17 @@
|
|||
use crate::utils::poly::{b64_2_num, get_coefficients};
|
||||
use crate::utils::poly::{b64_2_num, block_2_polynomial, get_coefficients};
|
||||
use anyhow::Result;
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn block2poly(val: &Value) -> Result<Vec<u8>> {
|
||||
// Convert JSON data in to a u128
|
||||
// TODO: Transfer decoding into own function?
|
||||
let string: String = serde_json::from_value(val["block"].clone())?;
|
||||
let block = BASE64_STANDARD.decode(string)?;
|
||||
|
||||
let number = b64_2_num(&string)?;
|
||||
let semantic: String = serde_json::from_value(val["semantic"].clone())?;
|
||||
|
||||
let coefficients: Vec<u8> = get_coefficients(number);
|
||||
let coefficients: Vec<u8> = block_2_polynomial(block, &semantic)?; //get_coefficients(number);
|
||||
|
||||
Ok(coefficients)
|
||||
}
|
||||
|
|
@ -24,7 +26,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn block2poly_task01() -> Result<()> {
|
||||
let block: Value = json!({"block" : "ARIAAAAAAAAAAAAAAAAAgA=="});
|
||||
let block: Value = json!({"block" : "ARIAAAAAAAAAAAAAAAAAgA==", "semantic" : "xex"});
|
||||
let coefficients: Vec<u8> = vec![0, 9, 12, 127];
|
||||
assert_eq!(
|
||||
block2poly(&block)?,
|
||||
|
|
@ -35,4 +37,18 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block2poly_task02() -> Result<()> {
|
||||
let block: Value = json!({"block" : "ARIAAAAAAAAAAAAAAAAAgA==", "semantic" : "gcm"});
|
||||
let coefficients: Vec<u8> = vec![7, 11, 14, 120];
|
||||
assert_eq!(
|
||||
block2poly(&block)?,
|
||||
coefficients,
|
||||
"Coefficients were: {:?}",
|
||||
block2poly(&block)?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue