remove NonePod and use dummy signed pods (#272)
* remove NonePod and use dummy signed pods * apply suggestion by @arnaucube
This commit is contained in:
parent
03485d6fd3
commit
3b4edab1f5
6 changed files with 54 additions and 49 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, sync::LazyLock};
|
||||
|
||||
use itertools::Itertools;
|
||||
use num_bigint::RandBigInt;
|
||||
use num_bigint::{BigUint, RandBigInt};
|
||||
use rand::rngs::OsRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -28,7 +28,12 @@ use crate::{
|
|||
pub struct Signer(pub SecretKey);
|
||||
|
||||
impl Signer {
|
||||
fn _sign(&mut self, params: &Params, kvs: &HashMap<Key, Value>) -> Result<SignedPod> {
|
||||
fn sign_with_nonce(
|
||||
&mut self,
|
||||
params: &Params,
|
||||
nonce: BigUint,
|
||||
kvs: &HashMap<Key, Value>,
|
||||
) -> Result<SignedPod> {
|
||||
let mut kvs = kvs.clone();
|
||||
let pubkey = self.0.public_key();
|
||||
kvs.insert(Key::from(KEY_SIGNER), Value::from(pubkey));
|
||||
|
|
@ -37,7 +42,6 @@ impl Signer {
|
|||
let dict = Dictionary::new(params.max_depth_mt_containers, kvs)?;
|
||||
let id = RawValue::from(dict.commitment()); // PodId as Value
|
||||
|
||||
let nonce = OsRng.gen_biguint_below(&GROUP_ORDER);
|
||||
let signature: Signature = self.0.sign(id, &nonce);
|
||||
Ok(SignedPod {
|
||||
id: PodId(Hash::from(id)),
|
||||
|
|
@ -46,6 +50,10 @@ impl Signer {
|
|||
dict,
|
||||
})
|
||||
}
|
||||
fn _sign(&mut self, params: &Params, kvs: &HashMap<Key, Value>) -> Result<SignedPod> {
|
||||
let nonce = OsRng.gen_biguint_below(&GROUP_ORDER);
|
||||
self.sign_with_nonce(params, nonce, kvs)
|
||||
}
|
||||
|
||||
pub fn public_key(&self) -> Point {
|
||||
self.0.public_key()
|
||||
|
|
@ -77,6 +85,15 @@ struct Data {
|
|||
kvs: Dictionary,
|
||||
}
|
||||
|
||||
static DUMMY_POD: LazyLock<SignedPod> = LazyLock::new(dummy);
|
||||
|
||||
fn dummy() -> SignedPod {
|
||||
let nonce = BigUint::from(2u32);
|
||||
Signer(SecretKey(BigUint::from(1u32)))
|
||||
.sign_with_nonce(&Params::default(), nonce, &HashMap::new())
|
||||
.expect("valid")
|
||||
}
|
||||
|
||||
impl SignedPod {
|
||||
fn _verify(&self) -> Result<()> {
|
||||
// 1. Verify type
|
||||
|
|
@ -142,6 +159,12 @@ impl SignedPod {
|
|||
dict: data.kvs,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Generate a valid SignedPod with a public deterministic secret key and nonce and no other
|
||||
/// key-values than the default ones. This is used for padding.
|
||||
pub fn dummy() -> SignedPod {
|
||||
DUMMY_POD.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Pod for SignedPod {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue