Skip to content

Commit

Permalink
key: return a u64 from key.id()
Browse files Browse the repository at this point in the history
Key IDs are specified as 8-byte scalars in the spec, so we don't have to
treat them like opaque blobs of bytes.
  • Loading branch information
csssuf committed Apr 13, 2018
1 parent 2d6d921 commit 880c225
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use byteorder::{BigEndian, WriteBytesExt};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use digest::Digest;
use failure::Error;
use md5::Md5;
Expand Down Expand Up @@ -306,8 +306,8 @@ impl Key {
}
}

pub fn id(&self) -> Result<Vec<u8>, Error> {
match self.version {
pub fn id(&self) -> Result<u64, Error> {
let bytes = match self.version {
KeyVersion::V3 => match self.key_material {
KeyMaterial::Rsa(ref pubkey, _) => {
let n = pubkey.n.to_bytes_be();
Expand All @@ -320,7 +320,9 @@ impl Key {
let len = f.len();
f.split_off(len - 8)
}),
}
}?;

Ok(BigEndian::read_u64(&bytes))
}
}

Expand Down

0 comments on commit 880c225

Please sign in to comment.