From bedb788432ed2c66d2c592d2e4b8e6b800d5a79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 15 Apr 2020 18:55:15 +0200 Subject: [PATCH] crypto: Test the keys info for a device. --- src/crypto/device.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/crypto/device.rs b/src/crypto/device.rs index cfde349c..44bb8e3b 100644 --- a/src/crypto/device.rs +++ b/src/crypto/device.rs @@ -33,12 +33,6 @@ pub struct Device { trust_state: Arc>, } -impl Device { - pub fn keys(&self, algorithm: &KeyAlgorithm) -> Option<&String> { - self.keys.get(algorithm) - } -} - #[derive(Debug, Clone, Copy)] pub enum TrustState { Verified, @@ -55,6 +49,10 @@ impl Device { pub fn user_id(&self) -> &UserId { &self.user_id } + + pub fn keys(&self, algorithm: &KeyAlgorithm) -> Option<&String> { + self.keys.get(algorithm) + } } impl From<&DeviceKeys> for Device { @@ -94,7 +92,7 @@ pub(crate) mod test { use serde_json::json; use std::convert::{From, TryFrom}; - use crate::api::r0::keys::DeviceKeys; + use crate::api::r0::keys::{DeviceKeys, KeyAlgorithm}; use crate::crypto::device::Device; use crate::identifiers::UserId; @@ -138,5 +136,13 @@ pub(crate) mod test { assert_eq!(&user_id, device.user_id()); assert_eq!(device_id, device.device_id()); assert_eq!(device.algorithms.len(), 2); + assert_eq!( + device.keys(&KeyAlgorithm::Curve25519).unwrap(), + "wjLpTLRqbqBzLs63aYaEv2Boi6cFEbbM/sSRQ2oAKk4" + ); + assert_eq!( + device.keys(&KeyAlgorithm::Ed25519).unwrap(), + "nE6W2fCblxDcOFmeEtCHNl8/l8bXcu7GKyAswA4r3mM" + ); } }