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