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::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::traits::Hash
and so can be called directly as if it is a hash.
Example usage:
use bouncycastle_core::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.
This crate compiles with STD; ie it is explicitly not tagged as no_std and it makes use of Vec and other
dynamically-sized nice things.
Modules§
- hash_
factory - Hash factory for creating instances of algorithms that implement the
Hashtrait. - kdf_
factory - KDF factory for creating instances of algorithms that implement the
KDFtrait. - mac_
factory - MAC factory for creating instances of algorithms that implement the
MACtrait. - rng_
factory - RNG factory for creating instances of algorithms that implement the
RNGtrait. - xof_
factory - XOF factory for creating instances of algorithms that implement the
XOFtrait.
Enums§
- Factory
Error - Top-level error type for Factories.