mirror of
https://github.com/ShadowJonathan/conduit_toolbox.git
synced 2025-06-08 02:17:04 +03:00
Pending changes exported from your codespace
This commit is contained in:
parent
a04057ed4c
commit
9b8416cf4b
3 changed files with 87 additions and 0 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -45,6 +45,12 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
|
@ -120,6 +126,15 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conduit_keys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conduit_migrate"
|
||||
version = "0.1.0"
|
||||
|
|
11
tools/keys/Cargo.toml
Normal file
11
tools/keys/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "conduit_keys"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "2.33.3"
|
||||
anyhow = "1.0.41"
|
||||
base64 = "0.13.0"
|
61
tools/keys/src/main.rs
Normal file
61
tools/keys/src/main.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
use std::{fs::File, io::Read, path::Path};
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let matches = App::new("Conduit Key Wrangler")
|
||||
.subcommand(
|
||||
SubCommand::with_name("convert_synapse")
|
||||
.arg(
|
||||
Arg::with_name("in")
|
||||
.short("i")
|
||||
.long("in")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.long_help("The synapse key file to read from."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("out")
|
||||
.short("o")
|
||||
.long("out")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.long_help(
|
||||
"The DER key file to output to. (Creates or overwrites(!) the file)",
|
||||
),
|
||||
),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("convert_synapse") {
|
||||
let in_file = matches.value_of("in").expect("Was already required");
|
||||
let out_file = matches.value_of("out").expect("Was already required");
|
||||
|
||||
let in_path = Path::new(in_file).canonicalize()?;
|
||||
let out_path = Path::new(out_file).canonicalize()?;
|
||||
|
||||
if in_path.is_dir() {
|
||||
return Err(anyhow::anyhow!("input path is a directory"));
|
||||
} else if out_path.is_dir() {
|
||||
return Err(anyhow::anyhow!("output path exists, and is a directory"));
|
||||
}
|
||||
|
||||
let mut in_file = File::open(in_path)?;
|
||||
let mut out_file = File::create(out_path)?;
|
||||
|
||||
// 65K, arbitrary, don't load large files right off the bat
|
||||
if in_file.metadata()?.len() > (1 << 16) {
|
||||
return Err(anyhow::anyhow!(
|
||||
"input file is too large (>65KB) for a synapse signing key"
|
||||
));
|
||||
}
|
||||
|
||||
let mut data = Vec::new();
|
||||
|
||||
in_file.read_to_end(&mut data)?;
|
||||
|
||||
drop(in_file);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue