Skip to content

Commit

Permalink
Handle error for group public key (#18)
Browse files Browse the repository at this point in the history
Update group_public_key field in config to use VerifyingKey type
  • Loading branch information
natalieesk committed Jun 19, 2023
1 parent a66903e commit 93e3293
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 4 additions & 3 deletions participant/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use frost::{Error, Identifier};
use frost::{Error, Identifier, VerifyingKey};
use frost_ed25519 as frost;
use hex::FromHex;
use std::io::BufRead;
Expand All @@ -7,7 +7,7 @@ use std::io::BufRead;
pub struct Config {
pub identifier: Identifier,
pub public_key: [u8; 32],
pub group_public_key: [u8; 32],
pub group_public_key: VerifyingKey,
}

pub trait Logger {
Expand Down Expand Up @@ -41,7 +41,8 @@ pub fn request_inputs(input: &mut impl BufRead, logger: &mut dyn Logger) -> Resu

input.read_line(&mut group_public_key_input).unwrap();

let group_public_key = <[u8; 32]>::from_hex(group_public_key_input.trim()).unwrap();
let group_public_key = VerifyingKey::from_hex(group_public_key_input.trim())
.map_err(|_| Error::MalformedVerifyingKey)?; // TODO: Frost library needs to be updated with correct Error type

Ok(Config {
identifier: Identifier::try_from(identifier)?,
Expand Down
19 changes: 18 additions & 1 deletion participant/src/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use frost::VerifyingKey;
#[cfg(test)]
use frost::{Error, Identifier};
use frost_ed25519 as frost;
Expand All @@ -21,7 +22,7 @@ fn check_valid_inputs() {
.unwrap();
let identifier = Identifier::try_from(1).unwrap();
let group_public_key =
<[u8; 32]>::from_hex("15d21ccd7ee42959562fc8aa63224c8851fb3ec85a3faf66040d380fb9738673")
VerifyingKey::from_hex("15d21ccd7ee42959562fc8aa63224c8851fb3ec85a3faf66040d380fb9738673")
.unwrap();

let config = Config {
Expand Down Expand Up @@ -83,3 +84,19 @@ fn check_invalid_length_public_key() {
assert!(expected.is_err());
assert!(expected == Err(Error::MalformedVerifyingKey))
}

#[test]
fn check_invalid_length_group_public_key() {
let mut test_logger = TestLogger(Vec::new());

let identifier = "1";
let pub_key = "929dcc590407aae7d388761cddb0c0db6f5627aea8e217f4a033f2ec83d93509";
let group_pub_key = "123456";
let input = format!("{}\n{}\n{}\n", identifier, pub_key, group_pub_key);
let mut invalid_input = input.as_bytes();

let expected = request_inputs(&mut invalid_input, &mut test_logger);

assert!(expected.is_err());
assert!(expected == Err(Error::MalformedVerifyingKey))
}

0 comments on commit 93e3293

Please sign in to comment.