Skip to content

Commit ed12546

Browse files
committed
missing_docs for factory
1 parent b1e5483 commit ed12546

6 files changed

Lines changed: 56 additions & 13 deletions

File tree

crypto/factory/src/hash_factory.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,24 @@ use bouncycastle_sha2::{SHA224_NAME, SHA256_NAME, SHA384_NAME, SHA512_NAME};
3535
use bouncycastle_sha3 as sha3;
3636
use bouncycastle_sha3::{SHA3_224_NAME, SHA3_256_NAME, SHA3_384_NAME, SHA3_512_NAME};
3737

38-
/// All members must impl Hash.
38+
/// Wrapper object for all algorithms that impl [Hash].
3939
/// Note: no SHAKE because SHAKE is not NIST approved as a hash function. See FIPS 202 section A.2.
4040
pub enum HashFactory {
41+
///
4142
SHA224(sha2::SHA224),
43+
///
4244
SHA256(sha2::SHA256),
45+
///
4346
SHA384(sha2::SHA384),
47+
///
4448
SHA512(sha2::SHA512),
49+
///
4550
SHA3_224(sha3::SHA3_224),
51+
///
4652
SHA3_256(sha3::SHA3_256),
53+
///
4754
SHA3_384(sha3::SHA3_384),
55+
///
4856
SHA3_512(sha3::SHA3_512),
4957
}
5058

crypto/factory/src/kdf_factory.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,25 @@ use bouncycastle_sha3::{
5858
SHA3_224_NAME, SHA3_256_NAME, SHA3_384_NAME, SHA3_512_NAME, SHAKE128_NAME, SHAKE256_NAME,
5959
};
6060

61-
// All members must impl KDF.
61+
/// Wrapper object for all algorithms that impl [KDF].
6262
pub enum KDFFactory {
63+
///
6364
#[allow(non_camel_case_types)]
6465
HKDF_SHA256(hkdf::HKDF_SHA256),
66+
///
6567
#[allow(non_camel_case_types)]
6668
HKDF_SHA512(hkdf::HKDF_SHA512),
69+
///
6770
SHA3_224(sha3::SHA3_224),
71+
///
6872
SHA3_256(sha3::SHA3_256),
73+
///
6974
SHA3_384(sha3::SHA3_384),
75+
///
7076
SHA3_512(sha3::SHA3_512),
77+
///
7178
SHAKE128(sha3::SHAKE128),
79+
///
7280
SHAKE256(sha3::SHAKE256),
7381
}
7482

crypto/factory/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
//! get the either the default algorithm or the default algorithm at the 128-bit or 256-bit security level.
2525
//! It also exposes [AlgorithmFactory::new] which can be used to create an instance of the algorithm
2626
//! by string name according to the string constants associated with the respective factory type.
27+
//!
28+
//! This crate compiles with STD; ie it is explicitly not tagged as `no_std` and it makes use of `Vec` and other
29+
//! dynamically-sized nice things.
30+
31+
#![forbid(missing_docs)]
2732

2833
use bouncycastle_core::errors::MACError;
2934

@@ -34,13 +39,19 @@ pub mod rng_factory;
3439
pub mod xof_factory;
3540

3641
/*** String constants ***/
42+
///
3743
pub const DEFAULT: &str = "Default";
44+
///
3845
pub const DEFAULT_128_BIT: &str = "Default128Bit";
46+
///
3947
pub const DEFAULT_256_BIT: &str = "Default256Bit";
4048

49+
/// Top-level error type for Factories.
4150
#[derive(Debug)]
4251
pub enum FactoryError {
52+
///
4353
MACError(MACError),
54+
///
4455
UnsupportedAlgorithm(String),
4556
}
4657

@@ -50,17 +61,14 @@ impl From<MACError> for FactoryError {
5061
}
5162
}
5263

64+
///
5365
pub trait AlgorithmFactory: Sized + Default {
54-
// Get the default configured algorithm.
55-
// Not implemented because all factories MUST impl Default.
56-
// fn default() -> Self;
57-
5866
/// Get the default configured algorithm at the 128-bit security level.
5967
fn default_128_bit() -> Self;
6068

6169
/// Get the default configured algorithm at the 256-bit security level.
6270
fn default_256_bit() -> Self;
6371

64-
/// Create an instance of the algorithm by name.
72+
/// Get an instance of the algorithm by name.
6573
fn new(alg_name: &str) -> Result<Self, FactoryError>;
6674
}

crypto/factory/src/mac_factory.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,39 +83,51 @@ use bouncycastle_sha2 as sha2;
8383
use bouncycastle_sha3 as sha3;
8484

8585
/*** Defaults ***/
86+
///
8687
pub const DEFAULT_MAC_NAME: &str = HMAC_SHA256_NAME;
88+
///
8789
pub const DEFAULT_128BIT_MAC_NAME: &str = HMAC_SHA256_NAME;
90+
///
8891
pub const DEFAULT_256BIT_MAC_NAME: &str = HMAC_SHA256_NAME;
8992

9093
#[allow(non_camel_case_types)]
9194

95+
/// Wrapper object for all algorithms that impl [MAC].
9296
/// MACFactory deviates from the usual AlgorithmFactory trait because MAC objects do not have a no-arg constructor;
9397
/// instead they have a constructor that takes a [KeyMaterialTrait] and can return an error.
9498
pub enum MACFactory {
95-
// All members must impl MAC.
99+
///
96100
HMAC_SHA224(hmac::HMAC<sha2::SHA224>),
101+
///
97102
HMAC_SHA256(hmac::HMAC<sha2::SHA256>),
103+
///
98104
HMAC_SHA384(hmac::HMAC<sha2::SHA384>),
105+
///
99106
HMAC_SHA512(hmac::HMAC<sha2::SHA512>),
107+
///
100108
HMAC_SHA3_224(hmac::HMAC<sha3::SHA3_224>),
109+
///
101110
HMAC_SHA3_256(hmac::HMAC<sha3::SHA3_256>),
111+
///
102112
HMAC_SHA3_384(hmac::HMAC<sha3::SHA3_384>),
113+
///
103114
HMAC_SHA3_512(hmac::HMAC<sha3::SHA3_512>),
104115
}
105116

106117
impl MACFactory {
118+
/// Get the default MAC algorithm.
107119
pub fn default(key: &impl KeyMaterialTrait) -> Result<Self, FactoryError> {
108120
Self::new(DEFAULT_MAC_NAME, key)
109121
}
110-
122+
/// Get the default 128-bit MAC algorithm.
111123
pub fn default_128_bit(key: &impl KeyMaterialTrait) -> Result<Self, FactoryError> {
112124
Self::new(DEFAULT_128BIT_MAC_NAME, key)
113125
}
114-
126+
/// Get the default 256-bit MAC algorithm.
115127
pub fn default_256_bit(key: &impl KeyMaterialTrait) -> Result<Self, FactoryError> {
116128
Self::new(DEFAULT_256BIT_MAC_NAME, key)
117129
}
118-
130+
/// Get an instance of the algorithm by name.
119131
pub fn new(alg_name: &str, key: &impl KeyMaterialTrait) -> Result<Self, FactoryError> {
120132
match alg_name {
121133
DEFAULT => Self::default(key),

crypto/factory/src/rng_factory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ use bouncycastle_core::traits::{RNG, SecurityStrength};
5050
use bouncycastle_rng as rng;
5151
use bouncycastle_rng::{HASH_DRBG_SHA256_NAME, HASH_DRBG_SHA512_NAME};
5252

53-
/// All members must impl RNG.
53+
/// Wrapper object for all algorithms that impl [RNG].
5454
pub enum RNGFactory {
55+
///
5556
#[allow(non_camel_case_types)]
5657
HashDRBG_SHA256(rng::HashDRBG_SHA256),
58+
///
5759
#[allow(non_camel_case_types)]
5860
HashDRBG_SHA512(rng::HashDRBG_SHA512),
5961
}

crypto/factory/src/xof_factory.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ use bouncycastle_sha3 as sha3;
4141
use bouncycastle_sha3::{SHAKE128_NAME, SHAKE256_NAME};
4242

4343
/*** Defaults ***/
44+
///
4445
pub const DEFAULT_XOF_NAME: &str = SHAKE128_NAME;
46+
///
4547
pub const DEFAULT_128BIT_XOF_NAME: &str = SHAKE128_NAME;
48+
///
4649
pub const DEFAULT_256BIT_XOF_NAME: &str = SHAKE256_NAME;
4750

48-
// All members must impl XOF.
51+
/// Wrapper object for all algorithms that impl [XOF].
4952
pub enum XOFFactory {
53+
///
5054
SHAKE128(sha3::SHAKE128),
55+
///
5156
SHAKE256(sha3::SHAKE256),
5257
}
5358

0 commit comments

Comments
 (0)