Skip to content

Commit b23925f

Browse files
committed
Refactor derivation for unwrap safety
1 parent d092917 commit b23925f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/headers/lnurl_auth_jwt.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ fn linking_key_path(hashing_key: &PrivateKey, domain_name: &str) -> Result<Deriv
172172
let mut engine = HmacEngine::<sha256::Hash>::new(&hashing_key.inner[..]);
173173
engine.input(domain_name.as_bytes());
174174
let result = Hmac::<sha256::Hash>::from_engine(engine).to_byte_array();
175-
let children = (0..4)
176-
.map(|i| u32::from_be_bytes(result[(i * 4)..((i + 1) * 4)].try_into().unwrap()))
175+
// unwrap safety: We take 4-byte chunks, so TryInto for [u8; 4] never fails.
176+
let children = result
177+
.chunks_exact(4)
178+
.take(4)
179+
.map(|i| u32::from_be_bytes(i.try_into().unwrap()))
177180
.map(ChildNumber::from);
178181
Ok(DerivationPath::from_iter(children))
179182
}

0 commit comments

Comments
 (0)