Expand description
Factory crate for creating instances of different types. Factory objects behave like other crypto providers in that they take an algorithm by string name and return an instance of the corresponding type. Generally, there is one factory for each trait in bouncycastle_core_interface::traits.
All factories are based on the rust enum factory pattern where, for example, the hash_factory::HashFactory can hold any Hash type in the library, and hash_factory::HashFactory itself impls bouncycastle_core_interface::traits::Hash and so can be called directly as if it is a hash.
Example usage:
use bouncycastle_core_interface::traits::Hash;
use bouncycastle_factory::AlgorithmFactory;
use bouncycastle_factory::hash_factory::HashFactory;
let data: &[u8] = b"Hello, world!";
let h = HashFactory::new("SHA3-256").unwrap();
let output: Vec<u8> = h.hash(data);All other factory types similarly implement their underlying trait and thus behave the same way.
Additionally, all factory types implement AlgorithmFactory which exposes functions to get the either the default algorithm or the default algorithm at the 128-bit or 256-bit security level. It also exposes AlgorithmFactory::new which can be used to create an instance of the algorithm by string name according to the string constants associated with the respective factory type.
Modules§
- hash_
factory - Hash factory for creating instances of algorithms that implement the Hash trait.
- kdf_
factory - KDF factory for creating instances of algorithms that implement the KDF trait.
- mac_
factory - MAC factory for creating instances of algorithms that implement the MAC trait.
- rng_
factory - RNG factory for creating instances of algorithms that implement the RNG trait.
- xof_
factory - XOF factory for creating instances of algorithms that implement the XOF trait.