2021-05-19 14:10:48 +00:00
|
|
|
// Copyright 2021 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 thiserror::Error;
|
|
|
|
|
2021-05-20 13:02:14 +00:00
|
|
|
/// Error type describing errors that happen while QR data is being decoded.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum DecodingError {
|
2021-05-20 13:02:14 +00:00
|
|
|
/// Error decoding the QR code.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[cfg(feature = "decode_image")]
|
|
|
|
#[cfg_attr(feature = "docs", doc(cfg(decode_image)))]
|
|
|
|
#[error(transparent)]
|
|
|
|
Qr(#[from] rqrr::DeQRError),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The QR code data is missing the mandatory Matrix header.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error("the decoded QR code is missing the Matrix header")]
|
|
|
|
Header,
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The QR code data is containing an invalid, non UTF-8, flow id.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
Utf8(#[from] std::string::FromUtf8Error),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The QR code data is using an unsupported or invalid verification mode.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error("the QR code contains an invalid verification mode: {0}")]
|
|
|
|
Mode(u8),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The flow id is not a valid event ID.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
Identifier(#[from] ruma_identifiers::Error),
|
|
|
|
#[error(transparent)]
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The QR code data does not contain all the necessary fields.
|
2021-05-19 14:10:48 +00:00
|
|
|
Read(#[from] std::io::Error),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The QR code data uses an invalid shared secret.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error("the QR code contains a too short shared secret, length: {0}")]
|
|
|
|
SharedSecret(usize),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// The QR code data uses an invalid or unsupported version.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error("the QR code contains an invalid or unsupported version: {0}")]
|
|
|
|
Version(u8),
|
|
|
|
}
|
|
|
|
|
2021-05-20 13:02:14 +00:00
|
|
|
/// Error type describing errors that happen while QR data is being encoded.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum EncodingError {
|
2021-05-20 13:02:14 +00:00
|
|
|
/// Error generating a QR code from the data, likely because the data
|
|
|
|
/// doesn't fit into a QR code.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
Qr(#[from] qrcode::types::QrError),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// Error decoding the identity keys as base64.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
Base64(#[from] base64::DecodeError),
|
2021-05-20 13:02:14 +00:00
|
|
|
/// Error encoding the given flow id, the flow id is too large.
|
2021-05-19 14:10:48 +00:00
|
|
|
#[error("The verification flow id length can't be converted into a u16: {0}")]
|
|
|
|
FlowId(#[from] std::num::TryFromIntError),
|
|
|
|
}
|