Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP on encryption with command-line utility #227

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ required-features = ["cli"]
[dependencies]
amplify = { version = "3.13.0", features = ["stringly_conversions", "std"] }
strict_encoding = "2.0.0-alpha.2"
secp256k1 = { version = "0.24.1", features = ["global-context"], optional = true }
lnpbp_bech32 = { version = "0.9.0-alpha.1", path = "bech32" }
lnpbp_chain = { version = "0.9.0-alpha.1", path = "chain" }
lnpbp_elgamal = { version = "0.9.0", path = "elgamal", optional = true }
Expand All @@ -42,7 +43,7 @@ colorize = { version = "0.1.0", optional = true } # Used by cli only
[features]
default = ["zip"]
all = ["serde", "elgamal", "identity", "zip", "cli"]
cli = ["clap", "serde", "identity", "base64-compat", "base58", "serde_yaml", "serde_json", "amplify/hex", "colorize"]
cli = ["clap", "serde", "identity", "base64-compat", "base58", "serde_yaml", "serde_json", "amplify/hex", "colorize", "secp256k1"]
serde = ["serde_crate", "serde_with", "amplify/serde",
"lnpbp_bech32/serde", "lnpbp_chain/serde"]
identity = ["lnpbp_identity"]
Expand Down
2 changes: 1 addition & 1 deletion bech32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl From<Infallible> for Error {
}
}

/// Type for wrapping Vec<u8> data in cases you need to do a convenient
/// Type for wrapping `Vec<u8>` data in cases you need to do a convenient
/// enum variant display derives with `#[display(inner)]`
#[cfg_attr(
feature = "serde",
Expand Down
25 changes: 24 additions & 1 deletion src/bin/lnpbp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use lnpbp::{bech32, id};
use lnpbp_identity::{
EcAlgo, IdentityCert, IdentitySigner, SigCert, VerifyError,
};
use secp256k1::SECP256K1;
use serde::Serialize;
use strict_encoding::{StrictDecode, StrictEncode};

Expand Down Expand Up @@ -427,7 +428,29 @@ fn main() -> Result<(), Error> {
sig.verify(&cert, data)?;
println!("{}", "Signature is valid".green());
}
Command::Identity(_) => todo!("elgamal encryption support"),
Command::Identity(IdentityCommand::Encrypt {
armor,
identity_file,
cert,
message,
src_file,
dst_file,
}) => {
let fd = fs::File::open(identity_file)?;
let id = IdentitySigner::strict_decode(fd)?;
let mut input = file_str_or_stdin(src_file, message)?;
let mut data = vec![];
input.read_to_end(&mut data)?;
lnpbp_elgamal::encrypt(SECP256K1, &data, cert.pubkey())?;
}
Command::Identity(IdentityCommand::Decrypt {
armor,
identity_file,
cert,
message,
src_file,
dst_file,
}) => {}
Command::Convert {
data,
from,
Expand Down