Skip to content

Commit d2280a0

Browse files
authored
ssh-key: remove fingerprint feature (#27)
The relevant functionality is now enabled by default. This cuts down on the number of features and overall feature-related complexity, especially as fingerprints are important baseline functionality.
1 parent a4b09b1 commit d2280a0

13 files changed

Lines changed: 34 additions & 83 deletions

File tree

ssh-key/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rust-version = "1.60"
2020
[dependencies]
2121
base64ct = "1.4"
2222
pem-rfc7468 = "0.6"
23+
sha2 = { version = "0.10.6", default-features = false }
2324
zeroize = { version = "1", default-features = false }
2425

2526
# optional dependencies
@@ -36,7 +37,6 @@ rsa = { version = "0.7", optional = true }
3637
sec1 = { version = "0.3", optional = true, default-features = false, features = ["point"] }
3738
serde = { version = "1", optional = true }
3839
sha1 = { version = "0.10", optional = true, default-features = false }
39-
sha2 = { version = "0.10.6", optional = true, default-features = false, features = ["oid"] }
4040
signature = { version = "1.6.4", optional = true, default-features = false }
4141
subtle = { version = "2", optional = true, default-features = false }
4242

@@ -47,7 +47,7 @@ tempfile = "3"
4747
zeroize_derive = "1.3" # hack to make minimal-versions lint happy (pulled in by `ed25519-dalek`)
4848

4949
[features]
50-
default = ["ecdsa", "fingerprint", "std", "rand_core"]
50+
default = ["ecdsa", "rand_core", "std"]
5151
alloc = ["base64ct/alloc", "signature", "zeroize/alloc"]
5252
std = [
5353
"alloc",
@@ -65,9 +65,8 @@ dsa = ["dep:bigint", "dep:dsa", "dep:sha1", "signature/rand-preview"]
6565
ecdsa = ["dep:sec1"]
6666
ed25519 = ["dep:ed25519-dalek", "rand_core"]
6767
encryption = [ "alloc", "dep:aes", "dep:bcrypt-pbkdf", "dep:ctr", "rand_core"]
68-
fingerprint = ["dep:sha2"]
6968
getrandom = ["rand_core/getrandom"]
70-
rsa = ["dep:bigint", "dep:rsa"]
69+
rsa = ["dep:bigint", "dep:rsa", "sha2/oid"]
7170

7271
[package.metadata.docs.rs]
7372
all-features = true

ssh-key/src/certificate.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,15 @@ use crate::{
2020
public::{Encapsulation, KeyData},
2121
reader::{Base64Reader, Reader},
2222
writer::{base64_len, Writer},
23-
Algorithm, Error, Result, Signature,
23+
Algorithm, Error, Fingerprint, HashAlg, Result, Signature,
2424
};
2525
use alloc::{
2626
borrow::ToOwned,
2727
string::{String, ToString},
2828
vec::Vec,
2929
};
3030
use core::str::FromStr;
31-
32-
#[cfg(feature = "fingerprint")]
33-
use {
34-
crate::{Fingerprint, HashAlg},
35-
signature::Verifier,
36-
};
31+
use signature::Verifier;
3732

3833
#[cfg(feature = "serde")]
3934
use serde::{de, ser, Deserialize, Serialize};
@@ -372,8 +367,8 @@ impl Certificate {
372367
///
373368
/// See [`Certificate::validate_at`] documentation for important notes on
374369
/// how to properly validate certificates!
375-
#[cfg(all(feature = "fingerprint", feature = "std"))]
376-
#[cfg_attr(docsrs, doc(cfg(all(feature = "fingerprint", feature = "std"))))]
370+
#[cfg(feature = "std")]
371+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
377372
pub fn validate<'a, I>(&self, ca_fingerprints: I) -> Result<()>
378373
where
379374
I: IntoIterator<Item = &'a Fingerprint>,
@@ -409,8 +404,6 @@ impl Certificate {
409404
/// ## Returns
410405
/// - `Ok` if the certificate validated successfully
411406
/// - `Error::CertificateValidation` if the certificate failed to validate
412-
#[cfg(feature = "fingerprint")]
413-
#[cfg_attr(docsrs, doc(cfg(feature = "fingerprint")))]
414407
pub fn validate_at<'a, I>(&self, unix_timestamp: u64, ca_fingerprints: I) -> Result<()>
415408
where
416409
I: IntoIterator<Item = &'a Fingerprint>,
@@ -454,7 +447,6 @@ impl Certificate {
454447
///
455448
/// It is public only for testing purposes, and deliberately hidden from
456449
/// the documentation for that reason.
457-
#[cfg(feature = "fingerprint")]
458450
#[doc(hidden)]
459451
pub fn verify_signature(&self) -> Result<()> {
460452
let mut tbs_certificate = Vec::new();

ssh-key/src/certificate/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl Builder {
309309
cert.encode_tbs(&mut tbs_cert)?;
310310
cert.signature = signing_key.try_sign(&tbs_cert)?;
311311

312-
#[cfg(all(debug_assertions, feature = "fingerprint"))]
312+
#[cfg(debug_assertions)]
313313
cert.validate_at(
314314
cert.valid_after.into(),
315315
&[cert.signature_key.fingerprint(Default::default())],

ssh-key/src/certificate/unix_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl UnixTime {
5858
}
5959

6060
/// Get the current time as a Unix timestamp.
61-
#[cfg(all(feature = "std", feature = "fingerprint"))]
61+
#[cfg(all(feature = "std"))]
6262
pub fn now() -> Result<Self> {
6363
SystemTime::now().try_into()
6464
}

ssh-key/src/fingerprint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use {
3737
///
3838
/// When the `serde` feature of this crate is enabled, this type receives impls
3939
/// of [`Deserialize`][`serde::Deserialize`] and [`Serialize`][`serde::Serialize`].
40-
#[cfg_attr(docsrs, doc(cfg(feature = "fingerprint")))]
4140
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
4241
#[non_exhaustive]
4342
pub enum Fingerprint {

ssh-key/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,11 @@ mod cipher;
154154
mod decode;
155155
mod encode;
156156
mod error;
157+
mod fingerprint;
157158
mod kdf;
158159
mod reader;
159160
mod writer;
160161

161-
#[cfg(feature = "fingerprint")]
162-
mod fingerprint;
163162
#[cfg(feature = "alloc")]
164163
mod mpint;
165164
#[cfg(feature = "alloc")]
@@ -170,12 +169,14 @@ pub use crate::{
170169
authorized_keys::AuthorizedKeys,
171170
cipher::Cipher,
172171
error::{Error, Result},
172+
fingerprint::Fingerprint,
173173
kdf::Kdf,
174174
private::PrivateKey,
175175
public::PublicKey,
176176
};
177177
pub use base64ct::LineEnding;
178178
pub use pem_rfc7468 as pem;
179+
pub use sha2;
179180

180181
#[cfg(feature = "alloc")]
181182
pub use crate::{
@@ -185,8 +186,5 @@ pub use crate::{
185186
#[cfg(feature = "ecdsa")]
186187
pub use sec1;
187188

188-
#[cfg(feature = "fingerprint")]
189-
pub use crate::fingerprint::Fingerprint;
190-
191189
#[cfg(feature = "rand_core")]
192190
pub use rand_core;

ssh-key/src/private.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ use crate::{
139139
public,
140140
reader::Reader,
141141
writer::Writer,
142-
Algorithm, Cipher, Error, Kdf, PublicKey, Result,
142+
Algorithm, Cipher, Error, Fingerprint, HashAlg, Kdf, PublicKey, Result,
143143
};
144144
use core::str;
145145

@@ -149,9 +149,6 @@ use {
149149
zeroize::Zeroizing,
150150
};
151151

152-
#[cfg(feature = "fingerprint")]
153-
use crate::{Fingerprint, HashAlg};
154-
155152
#[cfg(feature = "rand_core")]
156153
use rand_core::{CryptoRng, RngCore};
157154

@@ -412,8 +409,6 @@ impl PrivateKey {
412409
/// Compute key fingerprint.
413410
///
414411
/// Use [`Default::default()`] to use the default hash function (SHA-256).
415-
#[cfg(feature = "fingerprint")]
416-
#[cfg_attr(docsrs, doc(cfg(feature = "fingerprint")))]
417412
pub fn fingerprint(&self, hash_alg: HashAlg) -> Fingerprint {
418413
self.public_key.fingerprint(hash_alg)
419414
}

ssh-key/src/public.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
decode::Decode,
2828
encode::Encode,
2929
reader::{Base64Reader, Reader},
30-
Algorithm, Error, Result,
30+
Algorithm, Error, Fingerprint, HashAlg, Result,
3131
};
3232
use core::str::FromStr;
3333

@@ -41,9 +41,6 @@ use {
4141
},
4242
};
4343

44-
#[cfg(feature = "fingerprint")]
45-
use crate::{Fingerprint, HashAlg};
46-
4744
#[cfg(all(feature = "alloc", feature = "serde"))]
4845
use serde::{de, ser, Deserialize, Serialize};
4946

@@ -211,8 +208,6 @@ impl PublicKey {
211208
/// Compute key fingerprint.
212209
///
213210
/// Use [`Default::default()`] to use the default hash function (SHA-256).
214-
#[cfg(feature = "fingerprint")]
215-
#[cfg_attr(docsrs, doc(cfg(feature = "fingerprint")))]
216211
pub fn fingerprint(&self, hash_alg: HashAlg) -> Fingerprint {
217212
self.key_data.fingerprint(hash_alg)
218213
}

ssh-key/src/public/key_data.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{Ed25519PublicKey, SkEd25519};
44
use crate::{
55
checked::CheckedSum, decode::Decode, encode::Encode, reader::Reader, writer::Writer, Algorithm,
6-
Error, Result,
6+
Error, Fingerprint, HashAlg, Result,
77
};
88

99
#[cfg(feature = "alloc")]
@@ -12,9 +12,6 @@ use super::{DsaPublicKey, RsaPublicKey};
1212
#[cfg(feature = "ecdsa")]
1313
use super::{EcdsaPublicKey, SkEcdsaSha2NistP256};
1414

15-
#[cfg(feature = "fingerprint")]
16-
use crate::{Fingerprint, HashAlg};
17-
1815
/// Public key data.
1916
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
2017
#[non_exhaustive]
@@ -99,8 +96,6 @@ impl KeyData {
9996
/// Compute key fingerprint.
10097
///
10198
/// Use [`Default::default()`] to use the default hash function (SHA-256).
102-
#[cfg(feature = "fingerprint")]
103-
#[cfg_attr(docsrs, doc(cfg(feature = "fingerprint")))]
10499
pub fn fingerprint(&self, hash_alg: HashAlg) -> Fingerprint {
105100
Fingerprint::new(hash_alg, self)
106101
}

ssh-key/src/writer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
33
use crate::Result;
44
use pem_rfc7468 as pem;
5+
use sha2::{Digest, Sha256, Sha512};
56

67
#[cfg(feature = "alloc")]
78
use alloc::vec::Vec;
89

9-
#[cfg(feature = "fingerprint")]
10-
use sha2::{Digest, Sha256, Sha512};
11-
1210
/// Get the estimated length of data when encoded as Base64.
1311
///
1412
/// This is an upper bound where the actual length might be slightly shorter.
@@ -50,15 +48,13 @@ impl Writer for Vec<u8> {
5048
}
5149
}
5250

53-
#[cfg(feature = "fingerprint")]
5451
impl Writer for Sha256 {
5552
fn write(&mut self, bytes: &[u8]) -> Result<()> {
5653
self.update(bytes);
5754
Ok(())
5855
}
5956
}
6057

61-
#[cfg(feature = "fingerprint")]
6258
impl Writer for Sha512 {
6359
fn write(&mut self, bytes: &[u8]) -> Result<()> {
6460
self.update(bytes);

0 commit comments

Comments
 (0)