2020-02-25 16:36:11 +00:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
use cjson::Error as CjsonError;
|
2020-03-23 15:14:10 +00:00
|
|
|
use olm_rs::errors::OlmSessionError;
|
|
|
|
use serde_json::Error as SerdeError;
|
2020-03-18 13:15:56 +00:00
|
|
|
use thiserror::Error;
|
2020-02-25 16:36:11 +00:00
|
|
|
|
2020-03-18 13:15:56 +00:00
|
|
|
use super::store::CryptoStoreError;
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, OlmError>;
|
2020-03-18 14:50:32 +00:00
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum OlmError {
|
|
|
|
#[error("signature verification failed")]
|
|
|
|
Signature(#[from] SignatureError),
|
|
|
|
#[error("failed to read or write to the crypto store {0}")]
|
|
|
|
Store(#[from] CryptoStoreError),
|
2020-03-21 15:41:48 +00:00
|
|
|
#[error("decryption failed likely because a Olm session was wedged")]
|
|
|
|
SessionWedged,
|
|
|
|
#[error("the Olm message has a unsupported type")]
|
|
|
|
UnsupportedOlmType,
|
2020-03-23 15:14:10 +00:00
|
|
|
#[error("the Encrypted message has been encrypted with a unsupported algorithm.")]
|
|
|
|
UnsupportedAlgorithm,
|
|
|
|
#[error("the Encrypted message doesn't contain a ciphertext for our device")]
|
|
|
|
MissingCiphertext,
|
|
|
|
#[error("can't finish Olm Session operation {0}")]
|
|
|
|
OlmSessionError(#[from] OlmSessionError),
|
|
|
|
#[error("error deserializing a string to json")]
|
|
|
|
JsonError(#[from] SerdeError),
|
|
|
|
#[error("the provided JSON value isn't an object")]
|
|
|
|
NotAnObject,
|
2020-03-18 14:50:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 13:15:56 +00:00
|
|
|
pub type VerificationResult<T> = std::result::Result<T, SignatureError>;
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
2020-02-25 16:36:11 +00:00
|
|
|
pub enum SignatureError {
|
2020-03-18 13:15:56 +00:00
|
|
|
#[error("the provided JSON value isn't an object")]
|
2020-02-25 16:36:11 +00:00
|
|
|
NotAnObject,
|
2020-03-18 13:15:56 +00:00
|
|
|
#[error("the provided JSON object doesn't contain a signatures field")]
|
2020-02-25 16:36:11 +00:00
|
|
|
NoSignatureFound,
|
2020-03-18 13:15:56 +00:00
|
|
|
#[error("the provided JSON object can't be converted to a canonical representation")]
|
2020-02-25 16:36:11 +00:00
|
|
|
CanonicalJsonError(CjsonError),
|
2020-03-18 13:15:56 +00:00
|
|
|
#[error("the signature didn't match the provided key")]
|
2020-02-25 16:36:11 +00:00
|
|
|
VerificationError,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<CjsonError> for SignatureError {
|
|
|
|
fn from(error: CjsonError) -> Self {
|
|
|
|
Self::CanonicalJsonError(error)
|
|
|
|
}
|
|
|
|
}
|