crypto: Use AlgorithmAndDeviceId to get the device signature.

master
Damir Jelić 2020-07-14 11:27:50 +02:00
parent ca85564a9f
commit 8206394918
1 changed files with 7 additions and 5 deletions

View File

@ -24,7 +24,7 @@ use serde_json::{json, Value};
#[cfg(test)] #[cfg(test)]
use super::OlmMachine; use super::OlmMachine;
use matrix_sdk_common::api::r0::keys::{DeviceKeys, KeyAlgorithm}; use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm};
use matrix_sdk_common::events::Algorithm; use matrix_sdk_common::events::Algorithm;
use matrix_sdk_common::identifiers::{DeviceId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, UserId};
@ -158,7 +158,10 @@ impl Device {
} }
fn is_signed_by_device(&self, json: &mut Value) -> Result<(), SignatureError> { fn is_signed_by_device(&self, json: &mut Value) -> Result<(), SignatureError> {
let signing_key = self.keys.get(&KeyAlgorithm::Ed25519).unwrap(); let signing_key = self
.keys
.get(&KeyAlgorithm::Ed25519)
.ok_or(SignatureError::MissingSigningKey)?;
let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?; let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;
let unsigned = json_object.remove("unsigned"); let unsigned = json_object.remove("unsigned");
@ -170,8 +173,7 @@ impl Device {
json_object.insert("unsigned".to_string(), u); json_object.insert("unsigned".to_string(), u);
} }
// TODO this should be part of ruma-client-api. let key_id = AlgorithmAndDeviceId(KeyAlgorithm::Ed25519, self.device_id.to_string());
let key_id_string = format!("{}:{}", KeyAlgorithm::Ed25519, self.device_id);
let signatures = signatures.ok_or(SignatureError::NoSignatureFound)?; let signatures = signatures.ok_or(SignatureError::NoSignatureFound)?;
let signature_object = signatures let signature_object = signatures
@ -181,7 +183,7 @@ impl Device {
.get(&self.user_id.to_string()) .get(&self.user_id.to_string())
.ok_or(SignatureError::NoSignatureFound)?; .ok_or(SignatureError::NoSignatureFound)?;
let signature = signature let signature = signature
.get(key_id_string) .get(key_id.to_string())
.ok_or(SignatureError::NoSignatureFound)?; .ok_or(SignatureError::NoSignatureFound)?;
let signature = signature.as_str().ok_or(SignatureError::NoSignatureFound)?; let signature = signature.as_str().ok_or(SignatureError::NoSignatureFound)?;