Struct clacc::Accumulator
source · pub struct Accumulator<T>where
T: BigInt,{ /* private fields */ }Expand description
An accumulator.
Elements may be added and deleted from the acculumator without increasing
the size of its internal parameters. That is, the number of digits in the
accumulation z will never exceed the number of digits in the modulus
n.
Implementations§
source§impl<T> Accumulator<T>where
T: BigInt,
impl<T> Accumulator<T>where
T: BigInt,
sourcepub fn with_private_key(p: T, q: T) -> Self
pub fn with_private_key(p: T, q: T) -> Self
Initialize an accumulator from private key parameters. All accumulators are able to add elements and verify witnesses. An accumulator constructed from a private key is able to delete elements and prove elements after their addition.
use clacc::{Accumulator, gmp::BigInt};
let p = vec![0x3d];
let q = vec![0x35];
let acc = Accumulator::<BigInt>::with_private_key(
p.as_slice().into(),
q.as_slice().into()
);sourcepub fn with_random_key(key_bits: Option<usize>) -> (Self, T, T)
pub fn with_random_key(key_bits: Option<usize>) -> (Self, T, T)
Create an accumulator from a randomly generated private key and return it along with the generated key parameters.
If key_bits is None, the bit size of the generated modulus is
3072.
use clacc::{Accumulator, BigInt as BigIntTrait, gmp::BigInt};
assert_eq!(Accumulator::<BigInt>::with_random_key(None)
.0
.get_public_key()
.size_in_bits(), 3072);
assert_eq!(Accumulator::<BigInt>::with_random_key(Some(4096))
.0
.get_public_key()
.size_in_bits(), 4096);sourcepub fn with_public_key(n: T) -> Self
pub fn with_public_key(n: T) -> Self
Initialize an accumulator from a public key. An accumulator constructed from a public key is only able to add elements and verify witnesses.
use clacc::{Accumulator, gmp::BigInt};
let n = vec![0x0c, 0xa1];
let acc = Accumulator::<BigInt>::with_public_key(
n.as_slice().into()
);sourcepub fn get_public_key(&self) -> &T
pub fn get_public_key(&self) -> &T
Get an accumulator’s public key.
sourcepub fn add<'a, M, N, S, V>(&mut self, v: &'a V) -> Witness<T>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
pub fn add<'a, M, N, S, V>(&mut self, v: &'a V) -> Witness<T>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
Add an element to an accumulator.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let n = vec![0x0c, 0xa1];
let mut acc = Accumulator::<BigInt>::with_public_key(
n.as_slice().into()
);
let x = b"abc".to_vec();
let w = acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.verify::<Mapper, U16, RawSerializer, _>(&x, &w).is_ok());This works with accumulators constructed from a public key or a private key.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let p = vec![0x3d];
let q = vec![0x35];
let mut acc = Accumulator::<BigInt>::with_private_key(
p.as_slice().into(),
q.as_slice().into()
);
let x = b"abc".to_vec();
let w = acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.verify::<Mapper, U16, RawSerializer, _>(&x, &w).is_ok());sourcepub fn del<'a, M, N, S, V>(
&mut self,
v: &'a V,
w: &Witness<T>
) -> Result<T, &'static str>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
pub fn del<'a, M, N, S, V>(
&mut self,
v: &'a V,
w: &Witness<T>
) -> Result<T, &'static str>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
Delete an element from an accumulator.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let p = vec![0x3d];
let q = vec![0x35];
let mut acc = Accumulator::<BigInt>::with_private_key(
p.as_slice().into(),
q.as_slice().into()
);
let x = b"abc".to_vec();
let w = acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.del::<Mapper, U16, RawSerializer, _>(&x, &w).is_ok());
assert!(acc.verify::<Mapper, U16, RawSerializer, _>(&x, &w).is_err());
assert!(acc.del::<Mapper, U16, RawSerializer, _>(&x, &w).is_err());This will only succeed with an accumulator constructed from a private key.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let n = vec![0x0c, 0xa1];
let mut acc = Accumulator::<BigInt>::with_public_key(
n.as_slice().into()
);
let x = b"abc".to_vec();
let w = acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.del::<Mapper, U16, RawSerializer, _>(&x, &w).is_err());sourcepub fn prove<'a, M, N, S, V>(&self, v: &'a V) -> Result<Witness<T>, &'static str>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
pub fn prove<'a, M, N, S, V>(&self, v: &'a V) -> Result<Witness<T>, &'static str>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
Generate a witness to an element’s addition to the accumulation.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let p = vec![0x3d];
let q = vec![0x35];
let mut acc = Accumulator::<BigInt>::with_private_key(
p.as_slice().into(),
q.as_slice().into()
);
let x = b"abc".to_vec();
acc.add::<Mapper, U16, RawSerializer, _>(&x);
let w = acc.prove::<Mapper, U16, RawSerializer, _>(&x).unwrap();
assert!(acc.verify::<Mapper, U16, RawSerializer, _>(&x, &w).is_ok());This will only succeed with an accumulator constructed from a private key.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let n = vec![0x0c, 0xa1];
let mut acc = Accumulator::<BigInt>::with_public_key(
n.as_slice().into()
);
let x = b"abc".to_vec();
acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.prove::<Mapper, U16, RawSerializer, _>(&x).is_err());sourcepub fn verify<'a, M, N, S, V>(
&self,
v: &'a V,
w: &Witness<T>
) -> Result<(), &'static str>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
pub fn verify<'a, M, N, S, V>(
&self,
v: &'a V,
w: &Witness<T>
) -> Result<(), &'static str>where
M: Mapper,
N: ArrayLength<u8>,
V: 'a,
S: ElementSerializer<V>,
Verify an element is a member of an accumulator.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let n = vec![0x0c, 0xa1];
let mut acc = Accumulator::<BigInt>::with_public_key(
n.as_slice().into()
);
let x = b"abc".to_vec();
let w = acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.verify::<Mapper, U16, RawSerializer, _>(&x, &w).is_ok());This works with accumulators constructed from a public key or a private key.
use clacc::{
Accumulator, RawSerializer,
blake2::Mapper,
gmp::BigInt,
typenum::U16,
};
let p = vec![0x3d];
let q = vec![0x35];
let mut acc = Accumulator::<BigInt>::with_private_key(
p.as_slice().into(),
q.as_slice().into()
);
let x = b"abc".to_vec();
let w = acc.add::<Mapper, U16, RawSerializer, _>(&x);
assert!(acc.verify::<Mapper, U16, RawSerializer, _>(&x, &w).is_ok());Trait Implementations§
source§impl<T: Clone> Clone for Accumulator<T>where
T: BigInt,
impl<T: Clone> Clone for Accumulator<T>where
T: BigInt,
source§fn clone(&self) -> Accumulator<T>
fn clone(&self) -> Accumulator<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more