From 880c225be0439d296ff69d44b9b200ee06b19b6f Mon Sep 17 00:00:00 2001 From: James Forcier Date: Fri, 13 Apr 2018 14:52:05 -0700 Subject: [PATCH] key: return a u64 from key.id() Key IDs are specified as 8-byte scalars in the spec, so we don't have to treat them like opaque blobs of bytes. --- src/key.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/key.rs b/src/key.rs index 88e2901..5c7081e 100644 --- a/src/key.rs +++ b/src/key.rs @@ -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; @@ -306,8 +306,8 @@ impl Key { } } - pub fn id(&self) -> Result, Error> { - match self.version { + pub fn id(&self) -> Result { + let bytes = match self.version { KeyVersion::V3 => match self.key_material { KeyMaterial::Rsa(ref pubkey, _) => { let n = pubkey.n.to_bytes_be(); @@ -320,7 +320,9 @@ impl Key { let len = f.len(); f.split_off(len - 8) }), - } + }?; + + Ok(BigEndian::read_u64(&bytes)) } }