Skip to content

Commit

Permalink
Merge #367: Hex validation for PrivateNoiseKey.
Browse files Browse the repository at this point in the history
380e02e Hex validation for `PrivateNoiseKey`. (Zshan0)

Pull request description:

  The input of `PrivateNoiseKey` present [here](https://github.com/revault/revault-gui/blob/master/src/installer/view.rs#L217) currently is only constraining the input to 64 bytes, but doesn't check if the string is a valid hex sequence.

  Based on the implementation of the validation for `noise_key` for `DefineCoordinator` present [here](https://github.com/revault/revault-gui/blob/master/src/installer/step/mod.rs#L315) the validation for hex sequence have been made as requested in #348

ACKs for top commit:
  edouardparis:
    ACK 380e02e

Tree-SHA512: 29b63aedbf7d6e7e110ceadc41130001d6208f0ec1c4f49733357db7d44cec8e390c245bd573f816975937deaf8fbba46ffb6726db952f04f17f4828210c6cde
  • Loading branch information
edouardparis committed May 27, 2022
2 parents a072a00 + 380e02e commit 0d3c1eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/installer/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,27 @@ impl Step for DefinePrivateNoiseKey {
fn update(&mut self, message: Message) {
if let Message::PrivateNoiseKey(msg) = message {
self.key.value = msg;
self.key.valid = self.key.value.as_bytes().len() == 64;

self.key.valid = true;
if let Ok(bytes) = Vec::from_hex(&self.key.value) {
if bytes.len() != 32 {
self.key.valid = false;
}
} else {
self.key.valid = false;
}
}
}
fn apply(&mut self, ctx: &mut Context, _config: &mut config::Config) -> bool {
self.key.valid = self.key.value.as_bytes().len() == 64;
self.key.valid = true;
if let Ok(bytes) = Vec::from_hex(&self.key.value) {
if bytes.len() != 32 {
self.key.valid = false;
}
} else {
self.key.valid = false;
}

ctx.private_noise_key = self.key.value.clone();
self.key.valid
}
Expand Down
4 changes: 3 additions & 1 deletion src/installer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ impl DefinePrivateNoiseKey {
.push(
Column::new().spacing(10).push(
form::Form::new(&mut self.key_input, "", key, Message::PrivateNoiseKey)
.warning("Key must be a 64 characters hex encoded string")
.warning(
"Please enter a 32 bytes noise private key that is hex encoded",
)
.size(20)
.padding(10)
.render(),
Expand Down

0 comments on commit 0d3c1eb

Please sign in to comment.