-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
452 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
Oops, something went wrong.