Enforce documentation and no unsafe code

This commit is contained in:
Jack Grigg 2023-12-05 18:30:28 +00:00
parent feea7316ea
commit ea3e731868
2 changed files with 15 additions and 7 deletions

View File

@ -1,18 +1,21 @@
//! Seed Fingerprints according to ZIP 32 //! Seed Fingerprints according to ZIP 32
//! //!
//! Implements section `Seed Fingerprints` of Shielded Hierarchical Deterministic Wallets (ZIP 32) //! Implements section [Seed Fingerprints] of Shielded Hierarchical Deterministic Wallets (ZIP 32).
//! //!
//! [Section Seed Fingerprints]: https://zips.z.cash/zip-0032#seed-fingerprints //! [Seed Fingerprints]: https://zips.z.cash/zip-0032#seed-fingerprints
use blake2b_simd::Params as Blake2bParams; use blake2b_simd::Params as Blake2bParams;
pub const ZIP32_SEED_FP_PERSONALIZATION: &[u8; 16] = b"Zcash_HD_Seed_FP"; const ZIP32_SEED_FP_PERSONALIZATION: &[u8; 16] = b"Zcash_HD_Seed_FP";
/// The fingerprint for a wallet's seed bytes, as defined in [ZIP 32].
///
/// [ZIP 32]: https://zips.z.cash/zip-0032#seed-fingerprints
pub struct SeedFingerprint([u8; 32]); pub struct SeedFingerprint([u8; 32]);
impl SeedFingerprint { impl SeedFingerprint {
/// Return the seed fingerprint of the wallet as defined in /// Derives the fingerprint of the given seed bytes.
/// <https://zips.z.cash/zip-0032#seed-fingerprints> or None ///
/// if the length of `seed_bytes` is less than 32 or /// Returns `None` if the length of `seed_bytes` is less than 32 or greater than 252.
/// greater than 252.
pub fn from_seed(seed_bytes: &[u8]) -> Option<SeedFingerprint> { pub fn from_seed(seed_bytes: &[u8]) -> Option<SeedFingerprint> {
let seed_len = seed_bytes.len(); let seed_len = seed_bytes.len();

View File

@ -2,6 +2,8 @@
//! //!
//! [ZIP 32]: https://zips.z.cash/zip-0032 //! [ZIP 32]: https://zips.z.cash/zip-0032
#![deny(missing_docs)]
#![deny(unsafe_code)]
#![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::broken_intra_doc_links)]
use memuse::{self, DynamicUsage}; use memuse::{self, DynamicUsage};
@ -94,6 +96,7 @@ impl ChainCode {
} }
} }
/// The index for a particular diversifier.
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DiversifierIndex(pub [u8; 11]); pub struct DiversifierIndex(pub [u8; 11]);
@ -128,10 +131,12 @@ impl TryFrom<DiversifierIndex> for u32 {
} }
impl DiversifierIndex { impl DiversifierIndex {
/// Constructs the zero index.
pub fn new() -> Self { pub fn new() -> Self {
DiversifierIndex([0; 11]) DiversifierIndex([0; 11])
} }
/// Increments this index, failing on overflow.
pub fn increment(&mut self) -> Result<(), ()> { pub fn increment(&mut self) -> Result<(), ()> {
for k in 0..11 { for k in 0..11 {
self.0[k] = self.0[k].wrapping_add(1); self.0[k] = self.0[k].wrapping_add(1);