[][src]Struct clacc::Accumulator

pub struct Accumulator<T: BigInt = BigIntGmp> {
    pub z: T,
    // some fields omitted
}

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.

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]

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]

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]

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]

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

impl<T> Send for Accumulator<T>

impl<T> Sync for Accumulator<T>

impl<T> Unpin for Accumulator<T> where
    T: Unpin

impl<T> UnwindSafe for Accumulator<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,