update cli to use async crypto

This commit is contained in:
brxken128 2023-01-24 16:19:30 +00:00
parent ecc6ac9a53
commit d8b6789cb7
No known key found for this signature in database
GPG key ID: 8B8D1AA6AE10A8FF
3 changed files with 10 additions and 6 deletions

1
Cargo.lock generated
View file

@ -841,6 +841,7 @@ dependencies = [
"hex",
"indoc",
"sd-crypto",
"tokio",
]
[[package]]

View file

@ -11,3 +11,4 @@ clap = { version = "4.0.32", features = ["derive"] }
anyhow = "1.0.68"
hex = "0.4.3"
sd-crypto = { path = "../../crates/crypto" }
tokio = { version = "1.21.2", features = ["io-util", "rt-multi-thread"] }

View file

@ -2,7 +2,8 @@ use anyhow::{Context, Result};
use clap::Parser;
use indoc::printdoc;
use sd_crypto::header::file::FileHeader;
use std::{fs::File, path::PathBuf};
use std::path::PathBuf;
use tokio::fs::File;
#[derive(Parser)]
struct Args {
@ -10,17 +11,18 @@ struct Args {
path: PathBuf,
}
fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
let mut reader = File::open(args.path).context("unable to open file")?;
let (header, aad) = FileHeader::from_reader(&mut reader)?;
print_details(&header, &aad);
let mut reader = File::open(args.path).await.context("unable to open file")?;
let (header, aad) = FileHeader::from_reader(&mut reader).await?;
print_crypto_details(&header, &aad);
Ok(())
}
fn print_details(header: &FileHeader, aad: &[u8]) {
fn print_crypto_details(header: &FileHeader, aad: &[u8]) {
printdoc! {"
Header version: {version}
Encryption algorithm: {algorithm}