[−][src]Struct clacc::Accumulator
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
.
Fields
z: T
The current accumulation value.
n: T
Modulus.
Implementations
impl<T: BigInt> Accumulator<T>
[src]
pub fn with_private_key(p: T, q: T) -> Self
[src]
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; use clacc::bigint::BigIntGmp; let p = vec![0x3d]; let q = vec![0x35]; let acc = Accumulator::<BigIntGmp>::with_private_key( p.as_slice().into(), q.as_slice().into() );
pub fn with_random_key() -> (Accumulator<T>, T, T)
[src]
Create an accumulator from a randomly generated private key and return it along with the generated key parameters.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; Accumulator::<BigIntGmp>::with_random_key();
pub fn with_public_key(n: T) -> Self
[src]
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; use clacc::bigint::BigIntGmp; let n = vec![0x0c, 0xa1]; let acc = Accumulator::<BigIntGmp>::with_public_key( n.as_slice().into() );
pub fn add<Map: Mapper, N: ArrayLength<u8>>(&mut self, x: &[u8]) -> Witness<T>
[src]
Add an element to an accumulator.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let n = vec![0x0c, 0xa1]; let mut acc = Accumulator::<BigIntGmp>::with_public_key( n.as_slice().into() ); let x = b"abc"; let w = acc.add::<MapBlake2b, U16>(x); assert!(acc.verify::<MapBlake2b, U16>(x, &w).is_ok());
This works with accumulators constructed from a public key or a private key.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let p = vec![0x3d]; let q = vec![0x35]; let mut acc = Accumulator::<BigIntGmp>::with_private_key( p.as_slice().into(), q.as_slice().into() ); let x = b"abc"; let w = acc.add::<MapBlake2b, U16>(x); assert!(acc.verify::<MapBlake2b, U16>(x, &w).is_ok());
pub fn del<Map: Mapper, N: ArrayLength<u8>>(
&mut self,
x: &[u8],
w: &Witness<T>
) -> Result<(), &'static str>
[src]
&mut self,
x: &[u8],
w: &Witness<T>
) -> Result<(), &'static str>
Delete an element from an accumulator.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let p = vec![0x3d]; let q = vec![0x35]; let mut acc = Accumulator::<BigIntGmp>::with_private_key( p.as_slice().into(), q.as_slice().into() ); let x = b"abc"; let w = acc.add::<MapBlake2b, U16>(x); assert!(acc.del::<MapBlake2b, U16>(x, &w).is_ok()); assert!(acc.verify::<MapBlake2b, U16>(x, &w).is_err()); assert!(acc.del::<MapBlake2b, U16>(x, &w).is_err());
This will only succeed with an accumulator constructed from a private key.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let n = vec![0x0c, 0xa1]; let mut acc = Accumulator::<BigIntGmp>::with_public_key( n.as_slice().into() ); let x = b"abc"; let w = acc.add::<MapBlake2b, U16>(x); assert!(acc.del::<MapBlake2b, U16>(x, &w).is_err());
pub fn prove<Map: Mapper, N: ArrayLength<u8>>(
&self,
x: &[u8]
) -> Result<Witness<T>, &'static str>
[src]
&self,
x: &[u8]
) -> Result<Witness<T>, &'static str>
Generate a witness to an element's addition to the accumulation.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let p = vec![0x3d]; let q = vec![0x35]; let mut acc = Accumulator::<BigIntGmp>::with_private_key( p.as_slice().into(), q.as_slice().into() ); let x = b"abc"; acc.add::<MapBlake2b, U16>(x); let w = acc.prove::<MapBlake2b, U16>(x).unwrap(); assert!(acc.verify::<MapBlake2b, U16>(x, &w).is_ok());
This will only succeed with an accumulator constructed from a private key.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let n = vec![0x0c, 0xa1]; let mut acc = Accumulator::<BigIntGmp>::with_public_key( n.as_slice().into() ); let x = b"abc"; acc.add::<MapBlake2b, U16>(x); assert!(acc.prove::<MapBlake2b, U16>(x).is_err());
pub fn verify<Map: Mapper, N: ArrayLength<u8>>(
&self,
x: &[u8],
w: &Witness<T>
) -> Result<(), &'static str>
[src]
&self,
x: &[u8],
w: &Witness<T>
) -> Result<(), &'static str>
Verify an element is a member of an accumulator.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let n = vec![0x0c, 0xa1]; let mut acc = Accumulator::<BigIntGmp>::with_public_key( n.as_slice().into() ); let x = b"abc"; let w = acc.add::<MapBlake2b, U16>(x); assert!(acc.verify::<MapBlake2b, U16>(x, &w).is_ok());
This works with accumulators constructed from a public key or a private key.
use clacc::Accumulator; use clacc::bigint::BigIntGmp; use clacc::mapper::MapBlake2b; use clacc::typenum::U16; let p = vec![0x3d]; let q = vec![0x35]; let mut acc = Accumulator::<BigIntGmp>::with_private_key( p.as_slice().into(), q.as_slice().into() ); let x = b"abc"; let w = acc.add::<MapBlake2b, U16>(x); assert!(acc.verify::<MapBlake2b, U16>(x, &w).is_ok());
Trait Implementations
impl<T: Clone + BigInt> Clone for Accumulator<T>
[src]
fn clone(&self) -> Accumulator<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug + BigInt> Debug for Accumulator<T>
[src]
impl<T: BigInt> Display for Accumulator<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Accumulator<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Accumulator<T>
impl<T> Sync for Accumulator<T>
impl<T> Unpin for Accumulator<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Accumulator<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,