solana-keygen - Poor mans keypair encryption (#6259)
* SDK: Refactor (read|write)_keypair Split file opening and data writing operations Drop filename == "-" stdio signal. It is an app-level feature * keygen: Move all non-key printing to stderr * keygen: Adapt to SDK refactor * keygen: Factor keypair output out to a helper function
This commit is contained in:
@ -1385,7 +1385,7 @@ mod tests {
|
||||
use serde_json::Value;
|
||||
use solana_client::mock_rpc_client_request::SIGNATURE;
|
||||
use solana_sdk::{
|
||||
signature::{gen_keypair_file, read_keypair},
|
||||
signature::{gen_keypair_file, read_keypair_file},
|
||||
transaction::TransactionError,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
@ -1442,7 +1442,7 @@ mod tests {
|
||||
// Test Balance Subcommand, incl pubkey and keypair-file inputs
|
||||
let keypair_file = make_tmp_path("keypair_file");
|
||||
gen_keypair_file(&keypair_file).unwrap();
|
||||
let keypair = read_keypair(&keypair_file).unwrap();
|
||||
let keypair = read_keypair_file(&keypair_file).unwrap();
|
||||
let test_balance = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
"balance",
|
||||
|
@ -2,7 +2,7 @@ use clap::ArgMatches;
|
||||
use solana_sdk::{
|
||||
native_token::sol_to_lamports,
|
||||
pubkey::Pubkey,
|
||||
signature::{read_keypair, Keypair, KeypairUtil},
|
||||
signature::{read_keypair_file, Keypair, KeypairUtil},
|
||||
};
|
||||
|
||||
// Return parsed values from matches at `name`
|
||||
@ -32,7 +32,7 @@ where
|
||||
// Return the keypair for an argument with filename `name` or None if not present.
|
||||
pub fn keypair_of(matches: &ArgMatches<'_>, name: &str) -> Option<Keypair> {
|
||||
if let Some(value) = matches.value_of(name) {
|
||||
read_keypair(value).ok()
|
||||
read_keypair_file(value).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -56,7 +56,7 @@ pub fn amount_of(matches: &ArgMatches<'_>, name: &str, unit: &str) -> Option<u64
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::{App, Arg};
|
||||
use solana_sdk::signature::write_keypair;
|
||||
use solana_sdk::signature::write_keypair_file;
|
||||
use std::fs;
|
||||
|
||||
fn app<'ab, 'v>() -> App<'ab, 'v> {
|
||||
@ -120,7 +120,7 @@ mod tests {
|
||||
fn test_keypair_of() {
|
||||
let keypair = Keypair::new();
|
||||
let outfile = tmp_file_path("test_gen_keypair_file.json", &keypair.pubkey());
|
||||
let _ = write_keypair(&keypair, &outfile).unwrap();
|
||||
let _ = write_keypair_file(&keypair, &outfile).unwrap();
|
||||
|
||||
let matches = app()
|
||||
.clone()
|
||||
@ -141,7 +141,7 @@ mod tests {
|
||||
fn test_pubkey_of() {
|
||||
let keypair = Keypair::new();
|
||||
let outfile = tmp_file_path("test_gen_keypair_file.json", &keypair.pubkey());
|
||||
let _ = write_keypair(&keypair, &outfile).unwrap();
|
||||
let _ = write_keypair_file(&keypair, &outfile).unwrap();
|
||||
|
||||
let matches = app()
|
||||
.clone()
|
||||
|
@ -1,5 +1,5 @@
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::read_keypair;
|
||||
use solana_sdk::signature::read_keypair_file;
|
||||
|
||||
// Return an error if a pubkey cannot be parsed.
|
||||
pub fn is_pubkey(string: String) -> Result<(), String> {
|
||||
@ -11,7 +11,7 @@ pub fn is_pubkey(string: String) -> Result<(), String> {
|
||||
|
||||
// Return an error if a keypair file cannot be parsed.
|
||||
pub fn is_keypair(string: String) -> Result<(), String> {
|
||||
read_keypair(&string)
|
||||
read_keypair_file(&string)
|
||||
.map(|_| ())
|
||||
.map_err(|err| format!("{:?}", err))
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use solana_cli::{
|
||||
display::{println_name_value, println_name_value_or},
|
||||
input_validators::is_url,
|
||||
};
|
||||
use solana_sdk::signature::{read_keypair, KeypairUtil};
|
||||
use solana_sdk::signature::{read_keypair_file, KeypairUtil};
|
||||
use std::error;
|
||||
|
||||
fn parse_settings(matches: &ArgMatches<'_>) -> Result<bool, Box<dyn error::Error>> {
|
||||
@ -94,7 +94,7 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<CliConfig, Box<dyn error::
|
||||
}
|
||||
default.keypair_path
|
||||
};
|
||||
let keypair = read_keypair(&keypair_path).or_else(|err| {
|
||||
let keypair = read_keypair_file(&keypair_path).or_else(|err| {
|
||||
Err(CliError::BadParameter(format!(
|
||||
"{}: Unable to open keypair file: {}",
|
||||
err, keypair_path
|
||||
|
Reference in New Issue
Block a user