mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
transparent, PublicKeyHashable -> PK
This commit is contained in:
parent
953e0b6f0a
commit
5ff8d2f8d0
@ -21,7 +21,7 @@ use thiserror::Error as ThisError;
|
||||
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum SignatureError {
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
Error(#[from] SigError),
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ pub enum TrustError {
|
||||
Expired(Duration, Duration),
|
||||
|
||||
/// Errors occured on signature verification
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
SignatureError(#[from] ed25519_dalek::SignatureError),
|
||||
|
||||
/// Errors occured on trust decoding from differrent formats
|
||||
@ -83,7 +83,7 @@ pub enum TrustError {
|
||||
#[error("Cannot decode a signature from bytes: {0}")]
|
||||
SignatureFromBytesError(#[from] SigError),
|
||||
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
PublicKeyError(#[from] PKError),
|
||||
|
||||
#[error(
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
use crate::certificate::CertificateError::{CertificateLengthError, Unexpected};
|
||||
use crate::certificate::{Certificate, CertificateError};
|
||||
use crate::public_key_hashable::PublicKeyHashable;
|
||||
use crate::public_key_hashable::PublicKeyHashable as PK;
|
||||
use crate::revoke::Revoke;
|
||||
use crate::revoke::RevokeError;
|
||||
use crate::trust::Trust;
|
||||
@ -96,11 +96,7 @@ where
|
||||
}
|
||||
|
||||
/// Insert new root weight
|
||||
pub fn add_root_weight(
|
||||
&mut self,
|
||||
pk: PublicKeyHashable,
|
||||
weight: Weight,
|
||||
) -> Result<(), TrustGraphError> {
|
||||
pub fn add_root_weight(&mut self, pk: PK, weight: Weight) -> Result<(), TrustGraphError> {
|
||||
Ok(self.storage.add_root_weight(pk, weight)?)
|
||||
}
|
||||
|
||||
@ -127,7 +123,7 @@ where
|
||||
|
||||
let mut chain = cert.borrow().chain.iter();
|
||||
let root_trust = chain.next().ok_or(EmptyChain)?;
|
||||
let root_pk: PublicKeyHashable = root_trust.issued_for.clone().into();
|
||||
let root_pk: PK = root_trust.issued_for.clone().into();
|
||||
|
||||
// Insert new TrustNode for this root_pk if there wasn't one
|
||||
if self.storage.get(&root_pk)?.is_none() {
|
||||
@ -225,7 +221,7 @@ where
|
||||
fn bf_search_paths(
|
||||
&self,
|
||||
node: &TrustNode,
|
||||
roots: HashSet<&PublicKeyHashable>,
|
||||
roots: HashSet<&PK>,
|
||||
) -> Result<Vec<Vec<Auth>>, TrustGraphError> {
|
||||
// queue to collect all chains in the trust graph (each chain is a path in the trust graph)
|
||||
let mut chains_queue: VecDeque<Vec<Auth>> = VecDeque::new();
|
||||
@ -273,7 +269,7 @@ where
|
||||
// - that trust must converge to one of the root weights
|
||||
// - there should be more than 1 trust in the chain
|
||||
let self_signed = last.issued_by == last.trust.issued_for;
|
||||
let issued_by: &PublicKeyHashable = last.issued_by.as_ref();
|
||||
let issued_by: &PK = last.issued_by.as_ref();
|
||||
let converges_to_root = roots.contains(issued_by);
|
||||
|
||||
if self_signed && converges_to_root && cur_chain.len() > 1 {
|
||||
@ -330,7 +326,7 @@ where
|
||||
pub fn revoke(&mut self, revoke: Revoke) -> Result<(), TrustGraphError> {
|
||||
Revoke::verify(&revoke)?;
|
||||
|
||||
let pk: PublicKeyHashable = revoke.pk.clone().into();
|
||||
let pk: PK = revoke.pk.clone().into();
|
||||
|
||||
Ok(self.storage.revoke(&pk, revoke)?)
|
||||
}
|
||||
|
@ -10,13 +10,13 @@ use trust_graph::{CertificateError, TrustGraphError};
|
||||
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum ServiceError {
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
PublicKeyDecodeError(#[from] PKError),
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
TGError(#[from] TrustGraphError),
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
CertError(#[from] CertificateError),
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
DtoError(#[from] DtoConversionError),
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error as ThisError;
|
||||
use trust_graph::{
|
||||
Auth, PublicKeyHashable, Revoke, Storage, StorageError, TrustGraph, TrustNode, Weight,
|
||||
Auth, PublicKeyHashable as PK, Revoke, Storage, StorageError, TrustGraph, TrustNode, Weight,
|
||||
};
|
||||
|
||||
static INSTANCE: OnceCell<Mutex<TrustGraph<SQLiteStorage>>> = OnceCell::new();
|
||||
@ -58,13 +58,13 @@ impl SQLiteStorage {
|
||||
|
||||
#[derive(ThisError, Debug)]
|
||||
pub enum SQLiteStorageError {
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
SQLiteError(InternalSqliteError),
|
||||
#[error("{0}")]
|
||||
PublicKeyFromStr(String),
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
EncodeError(RmpEncodeError),
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
DecodeError(RmpDecodeError),
|
||||
#[error("Cannot convert weight as integer from DB")]
|
||||
WeightConversionDB,
|
||||
@ -105,7 +105,7 @@ impl StorageError for SQLiteStorageError {}
|
||||
impl Storage for SQLiteStorage {
|
||||
type Error = SQLiteStorageError;
|
||||
|
||||
fn get(&self, pk: &PublicKeyHashable) -> Result<Option<TrustNode>, Self::Error> {
|
||||
fn get(&self, pk: &PK) -> Result<Option<TrustNode>, Self::Error> {
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("SELECT trustnode FROM trustnodes WHERE public_key = ?")?
|
||||
@ -131,7 +131,7 @@ impl Storage for SQLiteStorage {
|
||||
}
|
||||
}
|
||||
|
||||
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) -> Result<(), Self::Error> {
|
||||
fn insert(&mut self, pk: PK, node: TrustNode) -> Result<(), Self::Error> {
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("INSERT OR REPLACE INTO trustnodes VALUES (?, ?)")?
|
||||
@ -147,7 +147,7 @@ impl Storage for SQLiteStorage {
|
||||
Ok({})
|
||||
}
|
||||
|
||||
fn get_root_weight(&self, pk: &PublicKeyHashable) -> Result<Option<Weight>, Self::Error> {
|
||||
fn get_root_weight(&self, pk: &PK) -> Result<Option<Weight>, Self::Error> {
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("SELECT public_key,weight FROM roots WHERE public_key = ?")?
|
||||
@ -167,11 +167,7 @@ impl Storage for SQLiteStorage {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_root_weight(
|
||||
&mut self,
|
||||
pk: PublicKeyHashable,
|
||||
weight: Weight,
|
||||
) -> Result<(), Self::Error> {
|
||||
fn add_root_weight(&mut self, pk: PK, weight: Weight) -> Result<(), Self::Error> {
|
||||
log::info!("add root: {} weight: {}", pk, weight);
|
||||
let mut cursor = self
|
||||
.connection
|
||||
@ -187,7 +183,7 @@ impl Storage for SQLiteStorage {
|
||||
Ok({})
|
||||
}
|
||||
|
||||
fn root_keys(&self) -> Result<Vec<PublicKeyHashable>, Self::Error> {
|
||||
fn root_keys(&self) -> Result<Vec<PK>, Self::Error> {
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("SELECT public_key,weight FROM roots")?
|
||||
@ -198,8 +194,7 @@ impl Storage for SQLiteStorage {
|
||||
while let Some(row) = cursor.next()? {
|
||||
log::info!("row: {:?}", row);
|
||||
let pk = row[0].as_string().ok_or(PublicKeyConversion)?;
|
||||
let pk: PublicKeyHashable =
|
||||
PublicKeyHashable::from_str(pk).map_err(|e| PublicKeyFromStr(e.to_string()))?;
|
||||
let pk: PK = PK::from_str(pk).map_err(|e| PublicKeyFromStr(e.to_string()))?;
|
||||
|
||||
roots.push(pk)
|
||||
}
|
||||
@ -207,7 +202,7 @@ impl Storage for SQLiteStorage {
|
||||
Ok(roots)
|
||||
}
|
||||
|
||||
fn revoke(&mut self, pk: &PublicKeyHashable, revoke: Revoke) -> Result<(), Self::Error> {
|
||||
fn revoke(&mut self, pk: &PK, revoke: Revoke) -> Result<(), Self::Error> {
|
||||
match self.get(&pk)? {
|
||||
Some(mut trust_node) => {
|
||||
trust_node.update_revoke(revoke);
|
||||
@ -220,7 +215,7 @@ impl Storage for SQLiteStorage {
|
||||
|
||||
fn update_auth(
|
||||
&mut self,
|
||||
pk: &PublicKeyHashable,
|
||||
pk: &PK,
|
||||
auth: Auth,
|
||||
issued_for: &PublicKey,
|
||||
cur_time: Duration,
|
||||
|
Loading…
Reference in New Issue
Block a user