Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
johnschug committed Dec 14, 2023
1 parent 78b40ac commit 3eac7e1
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 153 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ maintenance = { status = "experimental" }
"v1_13" = []

[dev-dependencies]
structopt = "0.3"
clap = { version = "4.4.11", features = ["derive"] }
tempfile = "3"

[dependencies]
bitflags = "1"
bitflags = "2"
cfg-if = "1"
conv = "0.3"
cstr-argument = "0.1"
gpg-error = "0.6.0"
libc.workspace = true
memoffset = "0.7.1"
once_cell = "1"
memoffset = "0.9.0"
smallvec = "1"
static_assertions = "1.1"

Expand Down
16 changes: 7 additions & 9 deletions examples/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
use structopt;

use gpgme::{Context, Protocol};
use std::{
error::Error,
fs::File,
io::{self, prelude::*},
path::PathBuf,
};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
use clap::Parser;
use gpgme::{Context, Protocol};

#[derive(Debug, Parser)]
struct Cli {
#[structopt(long)]
#[arg(long)]
/// Use the CMS protocol
cms: bool,
#[structopt(parse(from_os_str))]
/// File to decrypt
filename: PathBuf,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
let args = Cli::parse();
let proto = if args.cms {
Protocol::Cms
} else {
Expand All @@ -31,7 +29,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut input = File::open(&args.filename)?;
let mut output = Vec::new();
ctx.decrypt(&mut input, &mut output)
.map_err(|e| format!("decrypting failed: {:?}", e))?;
.map_err(|e| format!("decrypting failed: {e:?}"))?;

println!("Begin Output:");
io::stdout().write_all(&output)?;
Expand Down
20 changes: 9 additions & 11 deletions examples/encrypt.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
use structopt;

use gpgme::{Context, Protocol};
use std::{
error::Error,
fs::File,
io::{self, prelude::*},
path::PathBuf,
};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
use clap::Parser;
use gpgme::{Context, Protocol};

#[derive(Debug, Parser)]
struct Cli {
#[structopt(long)]
#[arg(long)]
/// Use the CMS protocol
cms: bool,
#[structopt(short, long = "recipient")]
#[arg(short, long = "recipient")]
/// For whom to encrypt the messages
recipients: Vec<String>,
#[structopt(parse(from_os_str))]
/// Files to encrypt
filename: PathBuf,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
let args = Cli::parse();
let proto = if args.cms {
Protocol::Cms
} else {
Expand All @@ -44,10 +42,10 @@ fn main() -> Result<(), Box<dyn Error>> {

let filename = &args.filename;
let mut input = File::open(&args.filename)
.map_err(|e| format!("can't open file `{}': {:?}", filename.display(), e))?;
.map_err(|e| format!("can't open file `{}': {e:?}", filename.display()))?;
let mut output = Vec::new();
ctx.encrypt(&keys, &mut input, &mut output)
.map_err(|e| format!("encrypting failed: {:?}", e))?;
.map_err(|e| format!("encrypting failed: {e:?}"))?;

println!("Begin Output:");
io::stdout().write_all(&output)?;
Expand Down
19 changes: 9 additions & 10 deletions examples/export.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use structopt;

use gpgme::{Context, ExportMode, Protocol};
use std::{
error::Error,
io::{self, prelude::*},
};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
use clap::Parser;
use gpgme::{Context, ExportMode, Protocol};

#[derive(Debug, Parser)]
struct Cli {
#[structopt(long = "extern")]
#[arg(long = "extern")]
/// Send keys to the keyserver
external: bool,
#[structopt(min_values(1))]
#[arg(num_args(1..))]
/// Keys to export
users: Vec<String>,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
let args = Cli::parse();
let mode = if args.external {
ExportMode::EXTERN
} else {
Expand Down Expand Up @@ -47,11 +46,11 @@ fn main() -> Result<(), Box<dyn Error>> {
if mode.contains(ExportMode::EXTERN) {
println!("sending keys to keyserver");
ctx.export_keys_extern(&keys, mode)
.map_err(|e| format!("export failed: {:?}", e))?;
.map_err(|e| format!("export failed: {e:?}"))?;
} else {
let mut output = Vec::new();
ctx.export_keys(&keys, mode, &mut output)
.map_err(|e| format!("export failed: {:?}", e))?;
.map_err(|e| format!("export failed: {e:?}"))?;

println!("Begin Result:");
io::stdout().write_all(&output)?;
Expand Down
22 changes: 10 additions & 12 deletions examples/import.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
use gpgme;
use structopt;
use std::{error::Error, fs::File, path::PathBuf};

use clap::Parser;
use gpgme::{data, Context, Data, ImportFlags};
use std::{error::Error, fs::File, path::PathBuf};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
#[structopt(long)]
#[arg(long)]
/// Import from given URLs
url: bool,
#[structopt(short = "0")]
#[arg(short = '0')]
/// URLS are delimited by a null
nul: bool,
#[structopt(min_values(1), parse(from_os_str))]
#[arg(num_args(1..))]
filenames: Vec<PathBuf>,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
let args = Cli::parse();
let mode = if args.url {
if args.nul {
Some(data::Encoding::Url0)
Expand All @@ -31,14 +29,14 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut ctx = Context::from_protocol(gpgme::Protocol::OpenPgp)?;
for file in args.filenames {
println!("reading file `{}'", &file.display());
println!("reading file `{}'", file.display());

let input = File::open(file)?;
let mut data = Data::from_seekable_stream(input)?;
mode.map(|m| data.set_encoding(m));
print_import_result(
ctx.import(&mut data)
.map_err(|e| format!("import failed {:?}", e))?,
.map_err(|e| format!("import failed {e:?}"))?,
);
}
Ok(())
Expand Down Expand Up @@ -67,7 +65,7 @@ fn print_import_result(result: gpgme::ImportResult) {
if status.contains(ImportFlags::SECRET) {
print!(" secret");
}
println!("");
println!();
}
println!("key import summary:");
println!(" considered: {}", result.considered());
Expand Down
29 changes: 14 additions & 15 deletions examples/keylist.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
use structopt;
use std::error::Error;

use clap::Parser;
use gpgme::{Context, KeyListMode, Protocol};
use std::error::Error;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
#[structopt(long)]
#[arg(long)]
/// Use the CMS protocol
cms: bool,
#[structopt(long)]
#[arg(long)]
/// Use GPGME_KEYLIST_MODE_LOCAL
local: bool,
#[structopt(long = "extern")]
#[arg(long = "extern")]
/// Use GPGME_KEYLIST_MODE_EXTERN
external: bool,
#[structopt(long)]
#[arg(long)]
/// Use GPGME_KEYLIST_MODE_SIGS
sigs: bool,
#[structopt(long = "sig-notations")]
#[arg(long = "sig-notations")]
/// Use GPGME_KEYLIST_MODE_SIG_NOTATIONS
notations: bool,
#[structopt(long)]
#[arg(long)]
/// Use GPGME_KEYLIST_MODE_EPHEMERAL
ephemeral: bool,
#[structopt(long)]
#[arg(long)]
/// Use GPGME_KEYLIST_MODE_VALIDATE
validate: bool,
users: Vec<String>,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
let args = Cli::parse();
let proto = if args.cms {
Protocol::Cms
} else {
Expand Down Expand Up @@ -81,10 +80,10 @@ fn main() -> Result<(), Box<dyn Error>> {
if key.is_qualified() { " qualified" } else { "" }
);
for (i, user) in key.user_ids().enumerate() {
println!("userid {}: {}", i, user.id().unwrap_or("[none]"));
println!("valid {}: {:?}", i, user.validity())
println!("userid {i}: {}", user.id().unwrap_or("[none]"));
println!("valid {i}: {:?}", user.validity())
}
println!("");
println!();
}

if keys.finish()?.is_truncated() {
Expand Down
21 changes: 10 additions & 11 deletions examples/keysign.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use structopt;
use std::error::Error;

use clap::Parser;
use gpgme::{Context, Protocol};
use std::error::Error;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
#[structopt(long)]
#[arg(long)]
/// Use the CMS protocol
cms: bool,
#[structopt(long)]
#[arg(long)]
/// Key to use for signing. Default key is used otherwise
key: Option<String>,
/// Key to sign
keyid: String,
}

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
let args = Cli::parse();
let proto = if args.cms {
Protocol::Cms
} else {
Expand All @@ -27,18 +26,18 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut ctx = Context::from_protocol(proto)?;
let key_to_sign = ctx
.get_key(&args.keyid)
.map_err(|e| format!("no key matched given key-id: {:?}", e))?;
.map_err(|e| format!("no key matched given key-id: {e:?}"))?;

if let Some(key) = args.key {
let key = ctx
.get_secret_key(key)
.map_err(|e| format!("unable to find signing key: {:?}", e))?;
.map_err(|e| format!("unable to find signing key: {e:?}"))?;
ctx.add_signer(&key)
.map_err(|e| format!("add_signer() failed: {:?}", e))?;
.map_err(|e| format!("add_signer() failed: {e:?}"))?;
}

ctx.sign_key(&key_to_sign, None::<String>, Default::default())
.map_err(|e| format!("signing failed: {:?}", e))?;
.map_err(|e| format!("signing failed: {e:?}"))?;

println!("Signed key for {}", args.keyid);
Ok(())
Expand Down
Loading

0 comments on commit 3eac7e1

Please sign in to comment.