mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
source
This commit is contained in:
parent
5ff8d2f8d0
commit
8a15bf7e2a
@ -24,9 +24,9 @@ use thiserror::Error as ThisError;
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum PKError {
|
||||
#[error("Cannot decode public key from bytes: {0}")]
|
||||
FromBytesError(SignatureError),
|
||||
FromBytesError(#[source] SignatureError),
|
||||
#[error("Cannot decode public key from base58 format: {0}")]
|
||||
FromBase58Error(bs58::decode::Error),
|
||||
FromBase58Error(#[source] bs58::decode::Error),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -21,8 +21,12 @@ use thiserror::Error as ThisError;
|
||||
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum SignatureError {
|
||||
#[error(transparent)]
|
||||
Error(#[from] SigError),
|
||||
#[error("{0}")]
|
||||
Error(
|
||||
#[from]
|
||||
#[source]
|
||||
SigError,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
@ -46,7 +46,7 @@ pub enum CertificateError {
|
||||
#[error("Incorrect length of an array. Should be 2 bytes of a format, 4 bytes of a version and 104 bytes for each trust")]
|
||||
IncorrectByteLength,
|
||||
#[error("Error while decoding a trust in a certificate: {0}")]
|
||||
DecodeError(TrustError),
|
||||
DecodeError(#[source] TrustError),
|
||||
#[error("Certificate is expired. Issued at {issued_at} and expired at {expires_at}")]
|
||||
ExpirationError {
|
||||
expires_at: String,
|
||||
@ -55,15 +55,15 @@ pub enum CertificateError {
|
||||
#[error("Certificate does not contain a trusted root.")]
|
||||
NoTrustedRoot,
|
||||
#[error("Root trust did not pass verification: {0}")]
|
||||
MalformedRoot(TrustError),
|
||||
MalformedRoot(#[source] TrustError),
|
||||
#[error("There is no `issued_by` public key in a certificate")]
|
||||
KeyInCertificateError,
|
||||
#[error("The certificate must have at least 1 trust")]
|
||||
CertificateLengthError,
|
||||
#[error("Cannot convert trust number {0} from string: {1}")]
|
||||
DecodeTrustError(usize, TrustError),
|
||||
DecodeTrustError(usize, #[source] TrustError),
|
||||
#[error("Trust {0} in chain did not pass verification: {1}")]
|
||||
VerificationError(usize, TrustError),
|
||||
VerificationError(usize, #[source] TrustError),
|
||||
#[error("there cannot be paths without any nodes after adding verified certificates")]
|
||||
Unexpected,
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use thiserror::Error as ThisError;
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum RevokeError {
|
||||
#[error("Signature is incorrect: {0}")]
|
||||
IncorrectSignature(SignatureError),
|
||||
IncorrectSignature(#[source] SignatureError),
|
||||
}
|
||||
|
||||
/// "A document" that cancels trust created before.
|
||||
|
22
src/trust.rs
22
src/trust.rs
@ -67,24 +67,32 @@ pub enum TrustError {
|
||||
Expired(Duration, Duration),
|
||||
|
||||
/// Errors occured on signature verification
|
||||
#[error(transparent)]
|
||||
SignatureError(#[from] ed25519_dalek::SignatureError),
|
||||
#[error("{0}")]
|
||||
SignatureError(
|
||||
#[from]
|
||||
#[source]
|
||||
ed25519_dalek::SignatureError,
|
||||
),
|
||||
|
||||
/// Errors occured on trust decoding from differrent formats
|
||||
#[error("Cannot decode the public key: {0} in the trust: {1}")]
|
||||
DecodePublicKeyError(String, PKError),
|
||||
DecodePublicKeyError(String, #[source] PKError),
|
||||
|
||||
#[error("Cannot parse `{0}` field in the trust '{1}': {2}")]
|
||||
ParseError(String, String, ParseIntError),
|
||||
ParseError(String, String, #[source] ParseIntError),
|
||||
|
||||
#[error("Cannot decode `{0}` from base58 format in the trust '{1}': {2}")]
|
||||
Base58DecodeError(String, String, bs58::decode::Error),
|
||||
Base58DecodeError(String, String, #[source] bs58::decode::Error),
|
||||
|
||||
#[error("Cannot decode a signature from bytes: {0}")]
|
||||
SignatureFromBytesError(#[from] SigError),
|
||||
|
||||
#[error(transparent)]
|
||||
PublicKeyError(#[from] PKError),
|
||||
#[error("{0}")]
|
||||
PublicKeyError(
|
||||
#[from]
|
||||
#[source]
|
||||
PKError,
|
||||
),
|
||||
|
||||
#[error(
|
||||
"Trust length should be 104: public key(32) + signature(64) + expiration date(8), was: {0}"
|
||||
|
@ -21,7 +21,7 @@ use crate::revoke::Revoke;
|
||||
use crate::revoke::RevokeError;
|
||||
use crate::trust::Trust;
|
||||
use crate::trust_graph::TrustGraphError::{
|
||||
CertificateCheckError, EmptyChain, InternalStorageError, NoRoot, RevokeCheckError,
|
||||
CertificateCheckError, EmptyChain, InternalStorageError, NoRoot,
|
||||
};
|
||||
use crate::trust_graph_storage::Storage;
|
||||
use crate::trust_node::{Auth, TrustNode};
|
||||
@ -57,9 +57,17 @@ pub enum TrustGraphError {
|
||||
#[error("Chain is empty")]
|
||||
EmptyChain,
|
||||
#[error("Certificate check error: {0}")]
|
||||
CertificateCheckError(CertificateError),
|
||||
CertificateCheckError(
|
||||
#[from]
|
||||
#[source]
|
||||
CertificateError,
|
||||
),
|
||||
#[error("Error on revoking a trust: {0}")]
|
||||
RevokeCheckError(RevokeError),
|
||||
RevokeCheckError(
|
||||
#[from]
|
||||
#[source]
|
||||
RevokeError,
|
||||
),
|
||||
}
|
||||
|
||||
impl<T: StorageError + 'static> From<T> for TrustGraphError {
|
||||
@ -68,24 +76,12 @@ impl<T: StorageError + 'static> From<T> for TrustGraphError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CertificateError> for TrustGraphError {
|
||||
fn from(err: CertificateError) -> Self {
|
||||
CertificateCheckError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TrustGraphError> for String {
|
||||
fn from(err: TrustGraphError) -> Self {
|
||||
format!("{}", err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RevokeError> for TrustGraphError {
|
||||
fn from(err: RevokeError) -> Self {
|
||||
RevokeCheckError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl<S> TrustGraph<S>
|
||||
where
|
||||
|
@ -9,11 +9,23 @@ use thiserror::Error as ThisError;
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum DtoConversionError {
|
||||
#[error("Cannot convert base58 string to bytes: {0}")]
|
||||
Base58Error(#[from] bs58::decode::Error),
|
||||
Base58Error(
|
||||
#[from]
|
||||
#[source]
|
||||
bs58::decode::Error,
|
||||
),
|
||||
#[error("Cannot convert string to PublicKey: {0}")]
|
||||
PublicKeyDecodeError(#[from] PKError),
|
||||
PublicKeyDecodeError(
|
||||
#[from]
|
||||
#[source]
|
||||
PKError,
|
||||
),
|
||||
#[error("Cannot convert string to PublicKey: {0}")]
|
||||
SignatureDecodeError(#[from] SignatureError),
|
||||
SignatureDecodeError(
|
||||
#[from]
|
||||
#[source]
|
||||
SignatureError,
|
||||
),
|
||||
}
|
||||
|
||||
#[fce]
|
||||
|
@ -10,14 +10,30 @@ use trust_graph::{CertificateError, TrustGraphError};
|
||||
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum ServiceError {
|
||||
#[error(transparent)]
|
||||
PublicKeyDecodeError(#[from] PKError),
|
||||
#[error(transparent)]
|
||||
TGError(#[from] TrustGraphError),
|
||||
#[error(transparent)]
|
||||
CertError(#[from] CertificateError),
|
||||
#[error(transparent)]
|
||||
DtoError(#[from] DtoConversionError),
|
||||
#[error("{0}")]
|
||||
PublicKeyDecodeError(
|
||||
#[from]
|
||||
#[source]
|
||||
PKError,
|
||||
),
|
||||
#[error("{0}")]
|
||||
TGError(
|
||||
#[from]
|
||||
#[source]
|
||||
TrustGraphError,
|
||||
),
|
||||
#[error("{0}")]
|
||||
CertError(
|
||||
#[from]
|
||||
#[source]
|
||||
CertificateError,
|
||||
),
|
||||
#[error("{0}")]
|
||||
DtoError(
|
||||
#[from]
|
||||
#[source]
|
||||
DtoConversionError,
|
||||
),
|
||||
}
|
||||
|
||||
pub fn get_weight_impl(public_key: String) -> Result<Option<u32>, ServiceError> {
|
||||
|
@ -3,8 +3,8 @@
|
||||
// if there is an older trust - don't add received trust
|
||||
|
||||
use crate::storage_impl::SQLiteStorageError::{
|
||||
DecodeError, EncodeError, PublcKeyNotFound, PublicKeyConversion, PublicKeyFromStr, SQLiteError,
|
||||
TrustNodeConversion, WeightConversionDB,
|
||||
PublcKeyNotFound, PublicKeyConversion, PublicKeyFromStr, TrustNodeConversion,
|
||||
WeightConversionDB,
|
||||
};
|
||||
use core::convert::TryFrom;
|
||||
use fce_sqlite_connector;
|
||||
@ -58,14 +58,26 @@ impl SQLiteStorage {
|
||||
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum SQLiteStorageError {
|
||||
#[error(transparent)]
|
||||
SQLiteError(InternalSqliteError),
|
||||
#[error("{0}")]
|
||||
SQLiteError(
|
||||
#[from]
|
||||
#[source]
|
||||
InternalSqliteError,
|
||||
),
|
||||
#[error("{0}")]
|
||||
PublicKeyFromStr(String),
|
||||
#[error(transparent)]
|
||||
EncodeError(RmpEncodeError),
|
||||
#[error(transparent)]
|
||||
DecodeError(RmpDecodeError),
|
||||
#[error("{0}")]
|
||||
EncodeError(
|
||||
#[from]
|
||||
#[source]
|
||||
RmpEncodeError,
|
||||
),
|
||||
#[error("{0}")]
|
||||
DecodeError(
|
||||
#[from]
|
||||
#[source]
|
||||
RmpDecodeError,
|
||||
),
|
||||
#[error("Cannot convert weight as integer from DB")]
|
||||
WeightConversionDB,
|
||||
#[error("Cannot convert public key as binary from DB")]
|
||||
@ -76,24 +88,6 @@ pub enum SQLiteStorageError {
|
||||
PublcKeyNotFound,
|
||||
}
|
||||
|
||||
impl From<InternalSqliteError> for SQLiteStorageError {
|
||||
fn from(err: InternalSqliteError) -> Self {
|
||||
SQLiteError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RmpEncodeError> for SQLiteStorageError {
|
||||
fn from(err: RmpEncodeError) -> Self {
|
||||
EncodeError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RmpDecodeError> for SQLiteStorageError {
|
||||
fn from(err: RmpDecodeError) -> Self {
|
||||
DecodeError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SQLiteStorageError> for String {
|
||||
fn from(err: SQLiteStorageError) -> Self {
|
||||
err.into()
|
||||
|
Loading…
Reference in New Issue
Block a user