feat: add gcm semantic to b2p and p2b

This commit is contained in:
0xalivecow 2024-11-01 21:20:46 +01:00
parent 28a8753d55
commit 8db0bbaa63
No known key found for this signature in database
9 changed files with 299 additions and 206 deletions

View file

@ -1,8 +1,9 @@
use crate::utils::poly::{self};
use crate::utils::poly::{self, polynomial_2_block};
use anyhow::{Ok, Result};
use base64::prelude::*;
use serde_json::Value;
pub fn poly2block(args: &Value) -> String {
pub fn poly2block(args: &Value) -> Result<Vec<u8>> {
let coefficients: Vec<u8> = args["coefficients"]
.as_array()
.unwrap()
@ -10,5 +11,9 @@ pub fn poly2block(args: &Value) -> String {
.map(|x| x.as_u64().unwrap() as u8)
.collect();
BASE64_STANDARD.encode(poly::coefficient_to_binary(coefficients).to_ne_bytes())
let semantic: String = serde_json::from_value(args["semantic"].clone())?;
let result = polynomial_2_block(coefficients, &semantic).unwrap();
Ok(result)
}