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§

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()
);

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);

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()
);

Get an accumulator’s public key.

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());

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());

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());

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());

Return the accumulation value as a BigInt.

Set the accumulation value from a BigInt.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.