Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Nov 22, 2024
1 parent 6b4902a commit 5f4382b
Show file tree
Hide file tree
Showing 13 changed files with 452 additions and 311 deletions.
6 changes: 3 additions & 3 deletions crates/rules/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![feature(associated_type_defaults)]
#![feature(inherent_associated_types)]
// #![feature(inherent_associated_types)]

mod rules;

pub mod prelude {

pub(crate) use crate::rules::*;

pub(crate) use std::{borrow::Borrow, marker::PhantomData};
pub(crate) use thiserror::Error as ThisError;
}

#[allow(unused_imports)]
pub use prelude::*;
2 changes: 2 additions & 0 deletions crates/rules/src/rules/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use crate::prelude::*;

pub type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down
17 changes: 17 additions & 0 deletions crates/rules/src/rules/factor_rules_violation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(dead_code)]

use crate::prelude::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FactorRulesViolation<E> {
NotYetValid(E),
ForeverInvalid(E),
}

pub type FactorBuilderResult<E> = std::result::Result<(), FactorRulesViolation<E>>;

#[derive(Debug, Clone, Copy, PartialEq, Eq, ThisError)]
pub enum PrimaryRoleViolation {
#[error("Unknown")]
MoreThanOneDeviceFactorIsNotSupported,
}
27 changes: 27 additions & 0 deletions crates/rules/src/rules/has_rule_set_for_role.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

use crate::prelude::*;

pub trait HasRuleSetForRole<F: IsFactor>: Sized + IsRole {
type Violation;

fn violation_if_add_factor_to_threshold(
context: RoleWithFactorsBuilt<F, Self>,
factor: &F,
) -> FactorBuilderResult<Self::Violation> {
match factor.get_factor_source_kind() {
FactorSourceKind::Device => {
Self::violation_if_device_factor_to_threshold(&context, factor)?
}
FactorSourceKind::Ledger => {}
FactorSourceKind::Password => {}
FactorSourceKind::SecurityQuestions => {}
FactorSourceKind::OffDeviceMnemonic => {}
}
Ok(())
}

fn violation_if_device_factor_to_threshold(
context: &RoleWithFactorsBuilt<F, Self>,
factor: &F,
) -> FactorBuilderResult<Self::Violation>;
}
15 changes: 15 additions & 0 deletions crates/rules/src/rules/is_role.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::prelude::*;

pub trait IsRole {
fn role_kind() -> RoleKind;
}

pub trait IsRoleObjectSafe {
fn get_role_kind(&self) -> RoleKind;
}

impl<T: IsRole> IsRoleObjectSafe for T {
fn get_role_kind(&self) -> RoleKind {
T::role_kind()
}
}
Loading

0 comments on commit 5f4382b

Please sign in to comment.