Skip to content

Commit 09bf94c

Browse files
committed
progress on missing_docs. DOES NOT COMPILE
1 parent ed12546 commit 09bf94c

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

crypto/base64/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, Base64Error> {
9999
/// Return type for errors relating to Base64 encoding and decoding.
100100
#[derive(Debug)]
101101
pub enum Base64Error {
102-
/// the do_update() method must not be called on a block that contains padding.
102+
/// The [Base64Decoder::do_update] method must not be called on a block that contains padding.
103103
/// If this error is returned, then the provided input has not been processed and the caller must instead
104-
/// pass the same input to do_final(). Note that do_final() is tolerant of incomplete padding blocks,
105-
/// so even if an additional padding character is contained in the next chunk of input, do_final() will still produce
106-
/// the correct output -- ie any additional chunks held by the caller can be discarded.
104+
/// pass the same input to [Base64Decoder::do_final]. Note that do_final() is tolerant of incomplete padding blocks,
105+
/// so even if an additional padding character is contained in the next chunk of input, do_final()
106+
/// will still produce the correct output -- ie any additional chunks held by the caller can be discarded.
107107
PaddingEnconteredDuringDoUpdate,
108108

109109
/// Input contained a character that was not in the base64 alphabet. The index of the illegal character is included in the output.

crypto/hex/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
//! The decoder ignores whitespace and "\x".
2222
2323
#![forbid(unsafe_code)]
24+
#![forbid(missing_docs)]
2425

2526
use bouncycastle_utils::ct::Condition;
2627

28+
/// Return type for errors relating to Hex encoding and decoding.
2729
#[derive(Debug)]
2830
pub enum HexError {
31+
/// Invalid hex character encountered at the given index.
2932
InvalidHexCharacter(usize),
33+
/// Since hex encodes each byte as two characters, the input must have an even length.
3034
OddLengthInput,
35+
///
3136
InsufficientOutputBufferSize,
3237
}
3338

crypto/hkdf/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
//! ```
192192
193193
#![forbid(unsafe_code)]
194+
#![forbid(missing_docs)]
194195

195196
use bouncycastle_core::errors::{KDFError, KeyMaterialError, MACError, SuspendableError};
196197
use bouncycastle_core::key_material;
@@ -213,19 +214,26 @@ use bouncycastle_core::traits::XOF;
213214
/*** Constants ***/
214215
// Slightly hacky, but set this to accommodate the underlying hash primitive with the largest output size.
215216
// Would be better to somehow pull that at compile time from H, but I'm not sure how to do that.
217+
// todo can I delete this?
216218
const HMAC_BLOCK_LEN: usize = 64;
217219

218220
/*** String constants ***/
219221

222+
///
220223
pub const HKDF_SHA256_NAME: &str = "HKDF-SHA256";
224+
///
221225
pub const HKDF_SHA512_NAME: &str = "HKDF-SHA512";
222226

223227
/*** Types ***/
228+
/// Public type for HKDF using SHA256.
224229
#[allow(non_camel_case_types)]
225230
pub type HKDF_SHA256 = HKDF<SHA256>;
231+
/// Public type for HKDF using SHA512.
226232
#[allow(non_camel_case_types)]
227233
pub type HKDF_SHA512 = HKDF<SHA512>;
228234

235+
/// Internal struct for HKDF.
236+
/// Can, in theory, be instantiated with hash functions other than the ones provided by this crate (even custom ones).
229237
#[derive(Clone)]
230238
pub struct HKDF<H: Hash + HashAlgParams + Default> {
231239
// Optional because we can't construct an HMAC until they give us a key
@@ -336,6 +344,7 @@ impl<H: Hash + HashAlgParams + Default> Default for HKDF<H> {
336344
}
337345

338346
impl<H: Hash + HashAlgParams + Default> HKDF<H> {
347+
/// Creates a new, uninstantiated HKDF object.
339348
pub fn new() -> Self {
340349
Self { hmac: None, entropy: HkdfEntropyTracker::new(), state: HkdfStates::Uninitialized }
341350
}
@@ -379,10 +388,11 @@ impl<H: Hash + HashAlgParams + Default> HKDF<H> {
379388
}
380389

381390
/// Same as [HKDF::extract], but writes the output to a provided KeyMaterial buffer.
391+
/// Note that the provided KeyMaterial must be correctly sized to the hash function output length.
382392
pub fn extract_out(
383393
salt: &impl KeyMaterialTrait,
384394
ikm: &impl KeyMaterialTrait,
385-
prk: &mut impl KeyMaterialTrait,
395+
prk: &mut KeyMaterial<H::OUTPUT_LEN>,
386396
) -> Result<usize, MACError> {
387397
// PRK = HMAC-Hash(salt, IKM)
388398

@@ -625,18 +635,24 @@ impl<H: Hash + HashAlgParams + Default> HKDF<H> {
625635
Ok(0)
626636
}
627637

638+
/// Finish the HKDF-Extract phase and produce the output `prk`.
628639
#[allow(non_snake_case)]
629-
pub fn do_extract_final(self) -> Result<impl KeyMaterialTrait, MACError> {
640+
pub fn do_extract_final(self) -> Result<KeyMaterial<HMAC_BLOCK_LEN>, MACError> {
630641
let mut okm = KeyMaterial::<HMAC_BLOCK_LEN>::new();
631642
self.do_extract_final_out(&mut okm)?;
632643
Ok(okm)
633644
}
634645

646+
/// Finish the HKDF-Extract phase and fill the provided `prk`.
647+
/// Note that the provided KeyMaterial must be correctly sized to the HMAC block length.
635648
#[allow(non_snake_case)]
636-
pub fn do_extract_final_out(self, okm: &mut impl KeyMaterialTrait) -> Result<usize, MACError> {
649+
pub fn do_extract_final_out(
650+
self,
651+
okm: &mut KeyMaterial<HMAC_BLOCK_LEN>,
652+
) -> Result<usize, MACError> {
637653
if self.state == HkdfStates::Uninitialized {
638654
return Err(MACError::InvalidState(
639-
"Must call do_extract_init() before calling do_extract_complete().",
655+
"Must call do_extract_init() before calling do_extract_final().",
640656
));
641657
};
642658
debug_assert!(self.hmac.is_some());

0 commit comments

Comments
 (0)