Skip to content

Commit eda8830

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 eda8830

2 files changed

Lines changed: 4 additions & 20 deletions

File tree

ssh-key/src/certificate.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use alloc::{
1717
vec::Vec,
1818
};
1919
use core::{
20-
hash::{Hash, Hasher},
20+
hash::Hash,
2121
str::FromStr,
2222
};
2323
use encoding::{Base64Reader, CheckedSum, Decode, Encode, Reader, Writer};
@@ -119,7 +119,7 @@ use {
119119
/// human-readable formats like JSON and TOML.
120120
///
121121
/// [PROTOCOL.certkeys]: https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
122-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
122+
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
123123
pub struct Certificate {
124124
/// CA-provided random bitstring of arbitrary length
125125
/// (but typically 16 or 32 bytes).
@@ -518,23 +518,6 @@ impl Encode for Certificate {
518518
}
519519
}
520520

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-
538521
impl FromStr for Certificate {
539522
type Err = Error;
540523

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)