Skip to content

Commit da2828b

Browse files
authored
Generate and verify SSH and GPG signatures in integration tests (#219)
1 parent 2f9767c commit da2828b

18 files changed

+215
-202
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ float-cmp = "allow"
6161
large_enum_variant = "allow"
6262
missing-errors-doc = "allow"
6363
missing-panics-doc = "allow"
64+
must-use-candidate = "allow"
6465
needless-pass-by-value = "allow"
6566
pedantic = { level = "deny", priority = -1 }
6667
result-large-err = "allow"

src/directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Directory {
6565
hasher.finalize()
6666
}
6767

68-
pub(crate) fn new() -> Self {
68+
pub fn new() -> Self {
6969
Self::default()
7070
}
7171
}

src/display_secret.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
pub(crate) struct DisplaySecret(pub(crate) PrivateKey);
3+
pub struct DisplaySecret(pub(crate) PrivateKey);
44

55
impl Display for DisplaySecret {
66
fn fmt(&self, f: &mut Formatter) -> fmt::Result {

src/fingerprint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub struct Fingerprint(pub(crate) Hash);
66
impl Fingerprint {
77
pub(crate) const LEN: usize = Hash::LEN;
88

9-
#[must_use]
109
pub(crate) fn as_bytes(&self) -> &[u8; Self::LEN] {
1110
self.0.as_bytes()
1211
}

src/hash.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub struct Hash(blake3::Hash);
66
impl Hash {
77
pub(crate) const LEN: usize = blake3::OUT_LEN;
88

9-
#[must_use]
109
pub fn as_bytes(&self) -> &[u8; Self::LEN] {
1110
self.0.as_bytes()
1211
}

src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
//! long as the manifest itself is kept secure.
1414
//!
1515
//! The `filepack` library crate is not intended for general consumption, and
16-
//! exists mainly to facilitate code-sharing between the `filepack` binary and
17-
//! integration tests. As such, it provides no semantic versioning guarantees.
16+
//! exists only to facilitate code-sharing between the `filepack` binary and
17+
//! integration tests. As such, it should not be used by outside consumers, and
18+
//! provides no semantic versioning guarantees.
1819
1920
use {
2021
self::{
@@ -54,7 +55,7 @@ use {
5455
public_key_error::PublicKeyError,
5556
sign_options::SignOptions,
5657
signature_error::SignatureError,
57-
signature_scheme::{SignatureScheme, SignatureSchemeType},
58+
signature_scheme::SignatureSchemeType,
5859
style::Style,
5960
subcommand::Subcommand,
6061
tag::Tag,
@@ -105,7 +106,7 @@ pub use self::{
105106
directory::Directory, entry::Entry, error::Error, file::File, fingerprint::Fingerprint,
106107
hash::Hash, manifest::Manifest, message::Message, note::Note, private_key::PrivateKey,
107108
public_key::PublicKey, relative_path::RelativePath, serialized_message::SerializedMessage,
108-
signature::Signature,
109+
signature::Signature, signature_scheme::SignatureScheme,
109110
};
110111

111112
#[cfg(test)]
@@ -194,10 +195,6 @@ mod tag;
194195
mod ticked;
195196
mod utf8_path_ext;
196197

197-
#[cfg(test)]
198-
mod pgp;
199-
#[cfg(test)]
200-
mod ssh;
201198
#[cfg(test)]
202199
mod test;
203200

src/manifest.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ impl Manifest {
4141
files
4242
}
4343

44-
#[must_use]
4544
pub fn fingerprint(&self) -> Fingerprint {
4645
Fingerprint(self.files.fingerprint())
4746
}

src/message.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub struct Message {
77
}
88

99
impl Message {
10-
#[must_use]
1110
pub fn serialize(&self) -> SerializedMessage {
1211
let mut serializer =
1312
FingerprintSerializer::new(FingerprintPrefix::Message, Vec::new()).unwrap();

src/private_key.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ impl PrivateKey {
1010
self.0.to_bytes()
1111
}
1212

13-
pub(crate) fn display_secret(&self) -> DisplaySecret {
13+
pub fn display_secret(&self) -> DisplaySecret {
1414
DisplaySecret(self.clone())
1515
}
1616

17-
#[cfg(test)]
18-
pub(crate) fn from_bytes(bytes: [u8; Self::LEN]) -> Self {
19-
Self(ed25519_dalek::SigningKey::from_bytes(&bytes))
17+
pub fn from_bytes(bytes: [u8; Self::LEN]) -> Self {
18+
let inner = ed25519_dalek::SigningKey::from_bytes(&bytes);
19+
assert!(!inner.verifying_key().is_weak());
20+
Self(inner)
2021
}
2122

2223
pub(crate) fn generate() -> Self {
@@ -42,7 +43,6 @@ impl PrivateKey {
4243
Ok(private_key)
4344
}
4445

45-
#[must_use]
4646
pub fn public_key(&self) -> PublicKey {
4747
self.clone().into()
4848
}

src/public_key.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@ use super::*;
44
pub struct PublicKey(ed25519_dalek::VerifyingKey);
55

66
impl PublicKey {
7-
#[cfg(test)]
87
pub(crate) const LEN: usize = ed25519_dalek::PUBLIC_KEY_LENGTH;
98

10-
#[cfg(test)]
11-
pub(crate) fn from_bytes(bytes: [u8; Self::LEN]) -> Self {
12-
Self(ed25519_dalek::VerifyingKey::from_bytes(&bytes).unwrap())
9+
fn encode_bytes(bytes: [u8; Self::LEN]) -> Bech32Encoder {
10+
let mut encoder = Bech32Encoder::new(Bech32Type::PublicKey);
11+
encoder.bytes(&bytes);
12+
encoder
13+
}
14+
15+
pub fn from_bytes(bytes: [u8; Self::LEN]) -> Result<Self, PublicKeyError> {
16+
let format = || Self::encode_bytes(bytes).to_string();
17+
18+
let key = ed25519_dalek::VerifyingKey::from_bytes(&bytes)
19+
.map_err(DalekSignatureError)
20+
.context(public_key_error::Invalid { key: format() })?;
21+
22+
ensure! {
23+
!key.is_weak(),
24+
public_key_error::Weak { key: format() },
25+
}
26+
27+
Ok(Self(key))
1328
}
1429

15-
#[must_use]
1630
pub fn inner(&self) -> ed25519_dalek::VerifyingKey {
1731
self.0
1832
}
@@ -48,24 +62,13 @@ impl FromStr for PublicKey {
4862
let inner = decoder.byte_array()?;
4963
decoder.done()?;
5064

51-
let inner = ed25519_dalek::VerifyingKey::from_bytes(&inner)
52-
.map_err(DalekSignatureError)
53-
.context(public_key_error::Invalid { key })?;
54-
55-
ensure! {
56-
!inner.is_weak(),
57-
public_key_error::Weak { key },
58-
}
59-
60-
Ok(Self(inner))
65+
Self::from_bytes(inner)
6166
}
6267
}
6368

6469
impl Display for PublicKey {
6570
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
66-
let mut encoder = Bech32Encoder::new(Bech32Type::PublicKey);
67-
encoder.bytes(self.0.as_bytes());
68-
write!(f, "{encoder}")
71+
write!(f, "{}", Self::encode_bytes(*self.0.as_bytes()))
6972
}
7073
}
7174

0 commit comments

Comments
 (0)