Skip to content

Commit 2dbc778

Browse files
hugocaillardkantai
andauthored
refactor: apply suggestions from code review
Co-authored-by: Aaron Blankstein <kantai@gmail.com>
1 parent a46d67d commit 2dbc778

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

stacks-common/src/util/vrf.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ impl VRFProof {
282282
// |----------------------------|----------|---------------------------|
283283
// Gamma point c scalar s scalar
284284
let gamma_opt = CompressedEdwardsY::from_slice(&bytes[0..32])
285-
.unwrap()
286-
.decompress();
285+
.ok()
286+
.and_then(|y| y.decompress());
287287
if gamma_opt.is_none() {
288288
test_debug!("Invalid Gamma");
289289
return None;
@@ -299,8 +299,8 @@ impl VRFProof {
299299

300300
c_buf[..16].copy_from_slice(&bytes[32..(16 + 32)]);
301301
s_buf[..32].copy_from_slice(&bytes[48..(32 + 48)]);
302-
let c = ed25519_Scalar::from_canonical_bytes(c_buf).expect("Invalid C scalar");
303-
let s = ed25519_Scalar::from_canonical_bytes(s_buf).expect("Invalid S scalar");
302+
let c = ed25519_Scalar::from_canonical_bytes(c_buf).ok()?;
303+
let s = ed25519_Scalar::from_canonical_bytes(s_buf).ok()?;
304304

305305
Some(VRFProof { Gamma: gamma, c, s })
306306
}
@@ -388,7 +388,7 @@ impl VRF {
388388
}
389389

390390
let y = CompressedEdwardsY::from_slice(&hasher.finalize()[0..32]);
391-
if let Some(h) = y.unwrap().decompress() {
391+
if let Some(h) = y.ok().and_then(|y| y.decompress()) {
392392
break h;
393393
}
394394

0 commit comments

Comments
 (0)