|
|
@ -4,6 +4,7 @@ pub use edus::RoomEdus;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{pdu::PduBuilder, utils, Error, PduEvent, Result};
|
|
|
|
use crate::{pdu::PduBuilder, utils, Error, PduEvent, Result};
|
|
|
|
use log::error;
|
|
|
|
use log::error;
|
|
|
|
|
|
|
|
use ring::digest;
|
|
|
|
use ruma::{
|
|
|
|
use ruma::{
|
|
|
|
api::client::error::ErrorKind,
|
|
|
|
api::client::error::ErrorKind,
|
|
|
|
events::{
|
|
|
|
events::{
|
|
|
@ -21,9 +22,8 @@ use sled::IVec;
|
|
|
|
use state_res::{event_auth, Requester, StateEvent, StateMap, StateStore};
|
|
|
|
use state_res::{event_auth, Requester, StateEvent, StateMap, StateStore};
|
|
|
|
|
|
|
|
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
collections::{hash_map::DefaultHasher, BTreeMap, HashMap},
|
|
|
|
collections::{BTreeMap, HashMap},
|
|
|
|
convert::{TryFrom, TryInto},
|
|
|
|
convert::{TryFrom, TryInto},
|
|
|
|
hash::{Hash, Hasher},
|
|
|
|
|
|
|
|
mem,
|
|
|
|
mem,
|
|
|
|
result::Result as StdResult,
|
|
|
|
result::Result as StdResult,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -285,8 +285,10 @@ impl Rooms {
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
|
.is_none()
|
|
|
|
.is_none()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO use ring crate to hash
|
|
|
|
return utils::string_from_bytes(
|
|
|
|
return Ok(room_id.as_str().to_owned());
|
|
|
|
digest::digest(&digest::SHA256, room_id.as_bytes()).as_ref(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.map_err(|_| Error::bad_database("Empty state generated invalid string from hash."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let pdu_ids_to_hash = self
|
|
|
|
let pdu_ids_to_hash = self
|
|
|
@ -304,11 +306,13 @@ impl Rooms {
|
|
|
|
.collect::<Result<Vec<Vec<u8>>>>()
|
|
|
|
.collect::<Result<Vec<Vec<u8>>>>()
|
|
|
|
})??;
|
|
|
|
})??;
|
|
|
|
|
|
|
|
|
|
|
|
let mut hasher = DefaultHasher::new();
|
|
|
|
let hash = digest::digest(
|
|
|
|
pdu_ids_to_hash.hash(&mut hasher);
|
|
|
|
&digest::SHA256,
|
|
|
|
let hash = hasher.finish().to_string();
|
|
|
|
&pdu_ids_to_hash.into_iter().flatten().collect::<Vec<u8>>(),
|
|
|
|
|
|
|
|
);
|
|
|
|
// TODO not sure how you want to hash this
|
|
|
|
// TODO not sure how you want to hash this
|
|
|
|
Ok(hash)
|
|
|
|
utils::string_from_bytes(hash.as_ref())
|
|
|
|
|
|
|
|
.map_err(|_| Error::bad_database("State generated invalid string from hash."))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Checks if a room exists.
|
|
|
|
/// Checks if a room exists.
|
|
|
|