Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for hax: avoid explicit return calls #150

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: make get_id_cred return Result to avoid unwrap
  • Loading branch information
geonnave committed Nov 20, 2023
commit 7b4fdafee2b993494beb3c6ddf0d3cb455cc8c28
8 changes: 4 additions & 4 deletions consts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ mod helpers {
))
}

pub fn get_id_cred<'a>(cred: &'a [u8]) -> BytesIdCred {
let (_g, kid) = parse_cred(cred).unwrap();
[0xa1, 0x04, 0x41, kid]
pub fn get_id_cred<'a>(cred: &'a [u8]) -> Result<BytesIdCred, EDHOCError> {
let (_g, kid) = parse_cred(cred)?;
Ok([0xa1, 0x04, 0x41, kid])
}
}

Expand All @@ -399,7 +399,7 @@ mod test {
let (g_a, kid) = res.unwrap();
assert_eq!(g_a, G_A_TV);
assert_eq!(kid, ID_CRED_TV[3]);
assert_eq!(get_id_cred(CRED_TV), ID_CRED_TV);
assert_eq!(get_id_cred(CRED_TV).unwrap(), ID_CRED_TV);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/edhoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn r_prepare_message_2(
let prk_3e2m = compute_prk_3e2m(crypto, &salt_3e2m, r, &g_x);

// compute MAC_2
let mac_2 = compute_mac_2(crypto, &prk_3e2m, &get_id_cred(cred_r), cred_r, &th_2);
let mac_2 = compute_mac_2(crypto, &prk_3e2m, &get_id_cred(cred_r)?, cred_r, &th_2);

let ead_2 = r_prepare_ead_2();

Expand Down Expand Up @@ -267,7 +267,7 @@ pub fn r_process_message_3(
crypto,
&prk_4e3m,
&th_3,
&get_id_cred(valid_cred_i),
&get_id_cred(valid_cred_i)?,
valid_cred_i,
);

Expand Down Expand Up @@ -457,7 +457,7 @@ pub fn i_process_message_2(
let expected_mac_2 = compute_mac_2(
crypto,
&prk_3e2m,
&get_id_cred(valid_cred_r),
&get_id_cred(valid_cred_r)?,
&valid_cred_r,
&th_2,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<'a, Crypto: CryptoTrait> EdhocInitiatorBuildM3<'a, Crypto> {
match i_prepare_message_3(
self.state,
&mut self.crypto,
&get_id_cred(self.cred_i),
&get_id_cred(self.cred_i)?,
self.cred_i,
) {
Ok((state, message_3, prk_out)) => Ok((
Expand Down