aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/sign.rs
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2021-05-13 05:35:37 +0000
committerNicholas Rodrigues Lordello <[email protected]>2021-05-13 05:35:37 +0000
commit223cd670577c55d65762a056782124dc4c905f04 (patch)
tree1bc0cf9010c7af1c3ff2732856360b88c289b43e /src/cmd/sign.rs
parentacd9b487c189d7f82ae9187f0fffd0607478abc4 (diff)
Use input files for binary input and add utilities for hex encoding
Diffstat (limited to 'src/cmd/sign.rs')
-rw-r--r--src/cmd/sign.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs
index 355ec57..0fa002c 100644
--- a/src/cmd/sign.rs
+++ b/src/cmd/sign.rs
@@ -8,7 +8,7 @@ use crate::{
};
use anyhow::{anyhow, Context as _, Result};
use ethnum::U256;
-use std::convert::TryInto;
+use std::{convert::TryInto, path::PathBuf};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
@@ -40,15 +40,11 @@ enum Data {
/// Sign an Ethereum message.
Message {
- /// The message is encoded as a hexadecimal string.
- #[structopt(short, long)]
- hex: bool,
-
- /// The message to sign in the "eth_sign" scheme. This message will be
- /// prefixed with "\x19Ethereum Signed Message:\n" and its length before
- /// hashing and singing.
+ /// Path to the message to sign in the "eth_sign" scheme. This message
+ /// will be prefixed with "\x19Ethereum Signed Message:\n" and its
+ /// length before hashing and singing.
#[structopt(name = "MESSAGE")]
- message: String,
+ message: PathBuf,
},
/// Sign a raw data.
@@ -99,14 +95,10 @@ impl Data {
} => Ok(hash::keccak256(
&transaction.as_parameters().signing_message(*chain_id),
)),
- Data::Message { hex, message } => {
- let bytes = if *hex {
- cmd::permissive_hex(&message)?
- } else {
- message.clone().into_bytes().into_boxed_slice()
- };
+ Data::Message { message } => {
+ let bytes = cmd::read_input(&message)?;
- let mut buffer = Vec::new();
+ let mut buffer = Vec::with_capacity(46 + bytes.len());
buffer.extend_from_slice(b"\x19Ethereum Signed Message:\n");
buffer.extend_from_slice(bytes.len().to_string().as_bytes());
buffer.extend_from_slice(&bytes);