Skip to content

chore: improvements#51

Merged
lonerapier merged 22 commits into
mainfrom
fix/todos
Nov 24, 2025
Merged

chore: improvements#51
lonerapier merged 22 commits into
mainfrom
fix/todos

Conversation

@lonerapier
Copy link
Copy Markdown
Collaborator

@lonerapier lonerapier commented Nov 17, 2025

  • Removes redundant todos
  • add previously removed tests
  • Remove key from factor.output args
  • Mark entropy as None for derive factor type

Related PR: multifactor/MFKDF#28

Copy link
Copy Markdown
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far!

Comment thread mfkdf2/benches/factor_combination.rs Outdated
Comment thread mfkdf2/src/definitions/mfkdf_derived_key/mod.rs
let mut new_factors = vec![];

for (id, factor) in factors.values_mut().enumerate() {
for (id, (_, mut factor)) in factors.into_iter().enumerate() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a little awkward, why not iter_mut and drop the enumerate?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's because we need ownwership of factor to prevent any unnecessary clones.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, just to be fair cloning a ref is just cloning the pointer, right?

Comment thread mfkdf2/src/definitions/key.rs Outdated
Comment thread mfkdf2/src/definitions/uniffi_types.rs
fn include_params(&mut self, params: Self::Params) -> MFKDF2Result<()> {
// Store the policy parameters for derive phase
self.params = serde_json::to_string(&params).unwrap();
self.params = params.clone();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a redundant clone based on line 23 with HOTPParams below?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? self.params and from_value takes the ownership of the underlying Value, so the clone is needed. In next refactoring, the aim is to get rid of the Value and work with factor specific params, because Value is only needed for FFI boundaries and serialization.

Comment thread mfkdf2/src/derive/factors/hotp.rs Outdated
Comment thread mfkdf2/src/derive/factors/hotp.rs Outdated
Comment thread mfkdf2/src/derive/factors/totp.rs
Comment thread mfkdf2/src/derive/key.rs
shares_bytes.push(Some(material.data()));
} else {
material.factor_type.include_params(serde_json::from_str(&factor.params).unwrap())?;
material.factor_type.include_params(factor.params.clone())?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you swapped the order of some of this around you could probably rid of this clone.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that, but not possible :)

will have to modify include_params to take in a shared reference, but that would mean we'll have to clone the params inside the method anyway to add it in the factor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but cloning a ref?

@lonerapier
Copy link
Copy Markdown
Collaborator Author

Updates:

  • Mostly clippy improvements for needless copies/clones/casts.
  • Added HOTP/TOTP Config and building the config from options to remove any unwraps from the hot path. Any mismatch in the params in caught during building the factor at setup phase.
  • cleaning up some more todos.

Copy link
Copy Markdown
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvements! See latest feedback.

Comment thread mfkdf2-web/src/api.ts
Comment thread mfkdf2/src/definitions/mfkdf_derived_key/mod.rs Outdated

#[cfg_attr(feature = "bindings", derive(uniffi::Record))]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HOTPConfig {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this and HOTPOptions feels redundant

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to remove any unwraps from the params and output path in Final key derivation. So, had to create a similar config struct. What's a better solution?


#[cfg_attr(feature = "bindings", derive(uniffi::Record))]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HOTPParams {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... And HOTPParams. Unneeded?

Comment thread mfkdf2/src/lib.rs
Comment thread mfkdf2/src/error.rs
Comment on lines +5 to +11
pub struct ByteArray<const N: usize>(pub [u8; N]);

/// 32 byte key
pub type Key = ByteArray<32>;

/// 32 byte salt
pub type Salt = ByteArray<32>;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a generic ByteArray and wrapped Key and Salt.

@lonerapier
Copy link
Copy Markdown
Collaborator Author

lonerapier commented Nov 24, 2025

all review comments handled. Merging the PR!!

@lonerapier lonerapier merged commit 46f5212 into main Nov 24, 2025
10 checks passed
@lonerapier lonerapier deleted the fix/todos branch November 24, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants