fix: suggestions 2

This commit is contained in:
Pravdyvy 2025-11-26 14:27:09 +02:00
parent fc531021fb
commit 77570c48e9
2 changed files with 43 additions and 8 deletions

View File

@ -49,9 +49,15 @@ impl Display for ChainIndex {
}
}
impl Default for ChainIndex {
fn default() -> Self {
ChainIndex::from_str("/").expect("Root parsing failure")
}
}
impl ChainIndex {
pub fn root() -> Self {
ChainIndex::from_str("/").unwrap()
ChainIndex::default()
}
pub fn chain(&self) -> &[u32] {
@ -95,6 +101,23 @@ mod tests {
assert_eq!(chain_id.chain(), &[257]);
}
#[test]
fn test_chain_id_deser_failure_no_root() {
let chain_index_error = ChainIndex::from_str("257").err().unwrap();
assert!(matches!(chain_index_error, ChainIndexError::NoRootFound));
}
#[test]
fn test_chain_id_deser_failure_int_parsing_failure() {
let chain_index_error = ChainIndex::from_str("/hello").err().unwrap();
assert!(matches!(
chain_index_error,
ChainIndexError::ParseIntError(_)
));
}
#[test]
fn test_chain_id_next_in_line_correct() {
let chain_id = ChainIndex::from_str("/257").unwrap();

View File

@ -20,8 +20,14 @@ impl KeyNode for ChildKeysPrivate {
fn root(seed: [u8; 64]) -> Self {
let hash_value = hmac_sha512::HMAC::mac(seed, "NSSA_master_priv");
let ssk = SecretSpendingKey(*hash_value.first_chunk::<32>().unwrap());
let ccc = *hash_value.last_chunk::<32>().unwrap();
let ssk = SecretSpendingKey(
*hash_value
.first_chunk::<32>()
.expect("hash_value is 64 bytes, must be safe to get first 32"),
);
let ccc = *hash_value
.last_chunk::<32>()
.expect("hash_value is 64 bytes, must be safe to get last 32");
let nsk = ssk.generate_nullifier_secret_key();
let isk = ssk.generate_incoming_viewing_secret_key();
@ -57,9 +63,9 @@ impl KeyNode for ChildKeysPrivate {
.outgoing_viewing_secret_key
.into(),
)
.unwrap()
.expect("Key generated as scalar, must be valid representation")
+ Scalar::from_repr(self.value.0.private_key_holder.nullifier_secret_key.into())
.unwrap()
.expect("Key generated as scalar, must be valid representation")
* Scalar::from_repr(
self.value
.0
@ -67,7 +73,7 @@ impl KeyNode for ChildKeysPrivate {
.incoming_viewing_secret_key
.into(),
)
.unwrap();
.expect("Key generated as scalar, must be valid representation");
let mut input = vec![];
input.extend_from_slice(b"NSSA_seed_priv");
@ -76,8 +82,14 @@ impl KeyNode for ChildKeysPrivate {
let hash_value = hmac_sha512::HMAC::mac(input, self.ccc);
let ssk = SecretSpendingKey(*hash_value.first_chunk::<32>().unwrap());
let ccc = *hash_value.last_chunk::<32>().unwrap();
let ssk = SecretSpendingKey(
*hash_value
.first_chunk::<32>()
.expect("hash_value is 64 bytes, must be safe to get first 32"),
);
let ccc = *hash_value
.last_chunk::<32>()
.expect("hash_value is 64 bytes, must be safe to get last 32");
let nsk = ssk.generate_nullifier_secret_key();
let isk = ssk.generate_incoming_viewing_secret_key();