Skip to content

Commit 9498222

Browse files
committed
ssh-key: derive Hash for Certificate
Rather than hand-implement Signed-off-by: Ross Williams <ross@ross-williams.net>
1 parent b1c6f48 commit 9498222

2 files changed

Lines changed: 4 additions & 23 deletions

File tree

ssh-key/src/certificate.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ use alloc::{
1616
string::{String, ToString},
1717
vec::Vec,
1818
};
19-
use core::{
20-
hash::{Hash, Hasher},
21-
str::FromStr,
22-
};
19+
use core::{hash::Hash, str::FromStr};
2320
use encoding::{Base64Reader, CheckedSum, Decode, Encode, Reader, Writer};
2421
use signature::Verifier;
2522

@@ -119,7 +116,7 @@ use {
119116
/// human-readable formats like JSON and TOML.
120117
///
121118
/// [PROTOCOL.certkeys]: https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
122-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
119+
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
123120
pub struct Certificate {
124121
/// CA-provided random bitstring of arbitrary length
125122
/// (but typically 16 or 32 bytes).
@@ -518,23 +515,6 @@ impl Encode for Certificate {
518515
}
519516
}
520517

521-
impl Hash for Certificate {
522-
#[inline]
523-
fn hash<H: Hasher>(&self, state: &mut H) {
524-
self.public_key.hash(state);
525-
self.serial.hash(state);
526-
self.cert_type.hash(state);
527-
self.key_id.hash(state);
528-
self.valid_principals.hash(state);
529-
self.valid_after.hash(state);
530-
self.valid_before.hash(state);
531-
self.critical_options.hash(state);
532-
self.extensions.hash(state);
533-
self.signature_key.hash(state);
534-
self.signature.hash(state);
535-
}
536-
}
537-
538518
impl FromStr for Certificate {
539519
type Err = Error;
540520

ssh-key/src/certificate/options_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use crate::{Error, Result};
44
use alloc::{collections::BTreeMap, string::String, vec::Vec};
55
use core::{
66
cmp::Ordering,
7+
hash::Hash,
78
ops::{Deref, DerefMut},
89
};
910
use encoding::{CheckedSum, Decode, Encode, Reader, Writer};
1011

1112
/// Key/value map type used for certificate's critical options and extensions.
12-
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
13+
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
1314
pub struct OptionsMap(pub BTreeMap<String, String>);
1415

1516
impl OptionsMap {

0 commit comments

Comments
 (0)