crypto: Reorder the errors so unpickling now returns the timestamp error.

master
Damir Jelić 2020-09-02 12:11:06 +02:00
parent c652762255
commit 8c4acf54e0
3 changed files with 24 additions and 10 deletions

View File

@ -115,6 +115,16 @@ pub enum EventError {
MissmatchedKeys,
}
#[derive(Error, Debug)]
pub enum SessionUnpicklingError {
/// The underlying Olm session operation returned an error.
#[error("can't finish Olm Session operation {0}")]
OlmSession(#[from] OlmSessionError),
/// The Session timestamp was invalid.
#[error("can't load session timestamps")]
SessionTimestampError,
}
#[derive(Error, Debug)]
pub enum SignatureError {
#[error("the signature used a unsupported algorithm")]

View File

@ -29,7 +29,7 @@ use serde_json::{json, Value};
use super::IdentityKeys;
use crate::{
error::{EventError, OlmResult},
error::{EventError, OlmResult, SessionUnpicklingError},
ReadOnlyDevice,
};
@ -192,8 +192,8 @@ impl Session {
/// Restore a Session from a previously pickled string.
///
/// Returns the restored Olm Session or a `OlmSessionError` if there was an
/// error.
/// Returns the restored Olm Session or a `SessionUnpicklingError` if there
/// was an error.
///
/// # Arguments
///
@ -213,17 +213,19 @@ impl Session {
our_identity_keys: Arc<IdentityKeys>,
pickle: PickledSession,
pickle_mode: PicklingMode,
) -> Result<Self, OlmSessionError> {
) -> Result<Self, SessionUnpicklingError> {
let session = OlmSession::unpickle(pickle.pickle.0, pickle_mode)?;
let session_id = session.session_id();
// FIXME this should use the UNIX epoch.
let now = Instant::now();
let creation_time = now.checked_sub(pickle.creation_time).unwrap();
// .ok_or(CryptoStoreError::SessionTimestampError)?;
let last_use_time = now.checked_sub(pickle.last_use_time).unwrap();
// .ok_or(CryptoStoreError::SessionTimestampError)?;
let creation_time = now
.checked_sub(pickle.creation_time)
.ok_or(SessionUnpicklingError::SessionTimestampError)?;
let last_use_time = now
.checked_sub(pickle.last_use_time)
.ok_or(SessionUnpicklingError::SessionTimestampError)?;
Ok(Session {
user_id,

View File

@ -34,6 +34,8 @@ use super::{
user_identity::UserIdentities,
};
use crate::error::SessionUnpicklingError;
pub mod memorystore;
#[cfg(not(target_arch = "wasm32"))]
@ -76,8 +78,8 @@ pub enum CryptoStoreError {
OlmGroupSession(#[from] OlmGroupSessionError),
/// A session time-stamp couldn't be loaded.
#[error("can't load session timestamps")]
SessionTimestampError,
#[error(transparent)]
SessionUnpickling(#[from] SessionUnpicklingError),
/// The store failed to (de)serialize a data type.
#[error(transparent)]