Skip to content

Commit

Permalink
[no ci] wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Nov 25, 2024
1 parent 212a875 commit b29bb93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 81 deletions.
75 changes: 11 additions & 64 deletions crates/rules/src/matrix_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ pub struct MatrixBuilderOrBuilt<T, U> {
#[doc(hidden)]
built: PhantomData<T>,

#[serde(skip)]
#[doc(hidden)]
role_of_current_builder: Option<RoleKind>,

primary_role: RoleBuilderOrBuilt<U>,
recovery_role: RoleBuilderOrBuilt<U>,
confirmation_role: RoleBuilderOrBuilt<U>,
Expand All @@ -23,85 +19,36 @@ pub struct MatrixBuilderOrBuilt<T, U> {
pub type MatrixWithFactors = MatrixBuilderOrBuilt<(), ()>;
pub type MatrixBuilder = MatrixBuilderOrBuilt<MatrixWithFactors, RoleWithFactors>;

impl MatrixBuilder {
pub(super) fn get_current_builder(&mut self) -> &mut RoleBuilder {
match self.role_of_current_builder {
Some(RoleKind::Primary) => &mut self.primary_role,
Some(RoleKind::Recovery) => &mut self.recovery_role,
Some(RoleKind::Confirmation) => &mut self.confirmation_role,
None => panic!("No role is currently being built"),
}
}
}
pub type MatrixBuilderMutateResult = Result<(), RoleBuilderValidation>;
pub type MatrixBuilderBuildResult = Result<MatrixWithFactors, RoleBuilderValidation>;

impl BuilderOfFactorsInRole for MatrixBuilder {
/// Typically we use `Self::new(RoleKind::Primary)` to create a new matrix builder.
fn new(role_of_current_builder: RoleKind) -> Self {
impl MatrixBuilder {
pub fn new() -> Self {
Self {
built: PhantomData,
role_of_current_builder: Some(role_of_current_builder),
primary_role: RoleBuilder::primary(),
recovery_role: RoleBuilder::recovery(),
confirmation_role: RoleBuilder::confirmation(),
}
}

fn build(self) -> RoleBuilderBuildResult {
pub fn build(self) -> MatrixBuilderBuildResult {
let primary = self.primary_role.build()?;
let recovery = self.recovery_role.build()?;
let confirmation = self.confirmation_role.build()?;
let built = MatrixWithFactors {
built: PhantomData,
role_of_current_builder: None,
primary_role: primary,
recovery_role: recovery,
confirmation_role: confirmation,
};
Ok(built)
}

fn role(&self) -> RoleKind {
todo!()
}

fn threshold(&self) -> u8 {
todo!()
}

fn threshold_factors(&self) -> Vec<&sargon::FactorSource> {
todo!()
}

fn override_factors(&self) -> Vec<&sargon::FactorSource> {
todo!()
}

fn validation_for_addition_of_factor_source_of_kind_to_override_for_recovery(
&self,
factor_source_kind: sargon::FactorSourceKind,
) -> RoleBuilderMutateResult {
todo!()
}

fn validation_for_addition_of_factor_source_of_kind_to_override_for_confirmation(
&self,
factor_source_kind: sargon::FactorSourceKind,
) -> RoleBuilderMutateResult {
todo!()
}

fn validation_for_addition_of_factor_source_of_kind_to_list_for_primary(
&self,
factor_source_kind: sargon::FactorSourceKind,
factor_list_kind: FactorListKind,
) -> RoleBuilderMutateResult {
todo!()
}

fn contains_factor_source(&self, factor_source: &sargon::FactorSource) -> bool {
todo!()
}

fn contains_factor_source_of_kind(&self, factor_source_kind: sargon::FactorSourceKind) -> bool {
todo!()
pub fn validate(&self) -> MatrixBuilderMutateResult {
self.primary_role.validate()?;
self.recovery_role.validate()?;
self.confirmation_role.validate()?;
Ok(())
}
}
17 changes: 0 additions & 17 deletions crates/rules/src/roles_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,23 +439,6 @@ mod private {
self.threshold = threshold;
}
}

// Implement for those same types, but no others.
impl UncheckedBuilderOfFactorsInRole for MatrixBuilder {
fn unchecked_add_factor_source_to_list(
&mut self,
factor_source: FactorSource,
factor_list_kind: FactorListKind,
) {
let role_builder = self.get_current_builder();
role_builder.unchecked_add_factor_source_to_list(factor_source, factor_list_kind);
}

fn unchecked_set_threshold(&mut self, threshold: u8) {
let role_builder = self.get_current_builder();
role_builder.unchecked_set_threshold(threshold);
}
}
}

// =======================
Expand Down

0 comments on commit b29bb93

Please sign in to comment.