Skip to content

Commit 792fc51

Browse files
Update dependencies (#18)
* Remove generic-array * Move assert deps to dev-dependencies * Update clap to 3.0.0 * Update hpke to v0.8.0
1 parent dc7be87 commit 792fc51

File tree

4 files changed

+51
-75
lines changed

4 files changed

+51
-75
lines changed

Cargo.lock

Lines changed: 28 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ description = "Tool to interact with the firewall matched data feature"
66
edition = "2021"
77

88
[dependencies]
9-
assert_cmd = "2.0.2"
10-
assert_fs = "1.0.6"
119
bincode = "1.3.3"
12-
clap = "3.0.0-beta.5"
13-
generic-array = { version = "0.14.4", features = ["serde"] }
14-
hpke = { version = "0.7.1", default-features = false, features = [
10+
clap = { version = "3.0.0", features = ["derive"] }
11+
hpke = { version = "0.8.0", default-features = false, features = [
1512
"x25519",
1613
"serde_impls",
1714
] }
@@ -20,5 +17,9 @@ rand = "0.8.4"
2017
serde = { version = "1.0.130", features = ["derive"] }
2118
serde_json = "1.0.68"
2219

20+
[dev-dependencies]
21+
assert_cmd = "2.0.2"
22+
assert_fs = "1.0.6"
23+
2324
[profile.release]
2425
lto = true

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ mod matched_data;
44

55
use crate::matched_data::generate_key_pair;
66
use clap::{ArgEnum, Parser};
7-
use hpke::kex::Serializable;
7+
use hpke::Serializable;
88
use serde::{Deserialize, Serialize};
99
use std::io::{stdin, stdout, Write};
1010
use std::{fs, str};
1111

1212
#[derive(Parser)]
13-
#[clap(author, version)]
13+
#[clap(about, author, version)]
1414
struct Options {
1515
#[clap(subcommand)]
1616
command: Command,
@@ -28,7 +28,7 @@ struct GenerateKeyPairOptions {
2828
short,
2929
long,
3030
value_name = "format",
31-
about = "Output format of key pair",
31+
help = "Output format of key pair",
3232
default_value = "json"
3333
)]
3434
output_format: KeyPairOutputFormat,
@@ -42,13 +42,13 @@ enum DecryptOutputFormat {
4242

4343
#[derive(Parser)]
4444
struct DecryptOptions {
45-
#[clap(about = "File containing the base64 encoded encrypted matched data")]
45+
#[clap(help = "File containing the base64 encoded encrypted matched data")]
4646
matched_data_filename: String,
4747

4848
#[clap(
4949
short = 'k',
5050
long,
51-
about = "File containing the base64 encoded private key"
51+
help = "File containing the base64 encoded private key"
5252
)]
5353
private_key_filename: String,
5454

@@ -57,7 +57,7 @@ struct DecryptOptions {
5757
short,
5858
long,
5959
value_name = "format",
60-
about = "Output format of matched data",
60+
help = "Output format of matched data",
6161
default_value = "utf8-lossy"
6262
)]
6363
output_format: DecryptOutputFormat,

src/matched_data.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,41 @@ use hpke::{
33
aead::{AeadTag, ChaCha20Poly1305},
44
kdf::HkdfSha256,
55
kem::X25519HkdfSha256,
6-
kex::{Deserializable, KeyExchange},
7-
setup_receiver, EncappedKey, HpkeError, Kem as KemTrait, OpModeR,
6+
setup_receiver, Deserializable, HpkeError, Kem as KemTrait, OpModeR,
87
};
98
use rand::{rngs::StdRng, SeedableRng};
109
use serde::{Deserialize, Serialize};
1110

1211
type Kem = X25519HkdfSha256;
1312
type Aead = ChaCha20Poly1305;
1413
type Kdf = HkdfSha256;
15-
type Kex = <Kem as KemTrait>::Kex;
14+
15+
type PrivateKey = <Kem as KemTrait>::PrivateKey;
16+
type PublicKey = <Kem as KemTrait>::PublicKey;
17+
type EncappedKey = <Kem as KemTrait>::EncappedKey;
1618

1719
#[derive(Serialize, Deserialize)]
1820
pub struct EncryptedData {
19-
encapped_key: EncappedKey<Kex>,
21+
encapped_key: EncappedKey,
2022
ciphertext: Vec<u8>,
2123
tag: AeadTag<Aead>,
2224
}
2325

2426
// Generates a public-private key pair
25-
pub fn generate_key_pair() -> (
26-
<Kex as KeyExchange>::PrivateKey,
27-
<Kex as KeyExchange>::PublicKey,
28-
) {
27+
pub fn generate_key_pair() -> (PrivateKey, PublicKey) {
2928
let mut csprng = StdRng::from_entropy();
3029
Kem::gen_keypair(&mut csprng)
3130
}
3231

3332
// Constructs a PrivateKey from an array of bytes
34-
pub fn get_private_key_from_bytes(
35-
private_key_bytes: &[u8],
36-
) -> Result<<Kex as KeyExchange>::PrivateKey, HpkeError> {
37-
<Kex as KeyExchange>::PrivateKey::from_bytes(private_key_bytes)
33+
pub fn get_private_key_from_bytes(private_key_bytes: &[u8]) -> Result<PrivateKey, HpkeError> {
34+
PrivateKey::from_bytes(private_key_bytes)
3835
}
3936

4037
// Decrypts data with provided private key
4138
pub fn decrypt_data(
4239
encrypted_data: &EncryptedData,
43-
private_key: &<Kex as KeyExchange>::PrivateKey,
40+
private_key: &PrivateKey,
4441
) -> Result<Vec<u8>, HpkeError> {
4542
// Decapsulate and derive the shared secret. Create a shared AEAD context.
4643
let mut aead_ctx = setup_receiver::<Aead, Kdf, Kem>(
@@ -52,7 +49,7 @@ pub fn decrypt_data(
5249

5350
// Decrypt ciphertext in place
5451
let mut ciphertext_copy = encrypted_data.ciphertext.clone();
55-
aead_ctx.open(&mut ciphertext_copy, &[], &encrypted_data.tag)?;
52+
aead_ctx.open_in_place_detached(&mut ciphertext_copy, &[], &encrypted_data.tag)?;
5653

5754
// Rename for clarity
5855
let plaintext = ciphertext_copy;

0 commit comments

Comments
 (0)