Skip to content

Make PBKDF hash field optional#477

Merged
jbaublitz merged 1 commit intostratis-storage:masterfrom
frankdavid:master
Apr 27, 2026
Merged

Make PBKDF hash field optional#477
jbaublitz merged 1 commit intostratis-storage:masterfrom
frankdavid:master

Conversation

@frankdavid
Copy link
Copy Markdown
Contributor

Fixes #473

The hash field is not always populated. The library should not try to create a String instance if hash is null.

@packit-as-a-service
Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo dnf install -y 'dnf*-command(copr)'
  • dnf copr enable packit/stratis-storage-libcryptsetup-rs-477
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@jbaublitz
Copy link
Copy Markdown
Member

@frankdavid Thanks for the contribution! I'll review this a little bit later today. Can you rebase onto the default branch in the meantime in preparation for merge?

Copy link
Copy Markdown
Member

@jbaublitz jbaublitz left a comment

Choose a reason for hiding this comment

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

Just two code simplification requests. I believe you also mentioned that other fields may be optional. Did it turn out that we only need to wrap the hash in an Option because all other fields can easily represent the default?

Comment thread src/settings.rs Outdated
let hash_cstring = self
.hash
.as_ref()
.map(|h| CString::new(h.as_bytes()).map_err(LibcryptErr::NullError))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this can be simplified with the to_cstring! macro.

Comment thread src/settings.rs Outdated
Comment on lines +48 to +52
let hash = if v.hash.is_null() {
None
} else {
Some(from_str_ptr!(v.hash)?.to_string())
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this block can be simplified with the ptr_to_option! macro in combination with the from_str_ptr! macro and transpose.

@mulkieran mulkieran moved this to In Progress in 2026April Apr 27, 2026
@frankdavid
Copy link
Copy Markdown
Contributor Author

frankdavid commented Apr 27, 2026

Did it turn out that we only need to wrap the hash in an Option because all other fields can easily represent the default?

I looked into it and the main issue is that the backing C API does not have official sentinel values. The integer fields contain 0 when the value is "empty" but I felt it's quite risky to interpret 0 as missing (what if the backing implementation starts using 0 as a non-empty value?).

With the current way, the Rust wrapper just lets the 0s through without interpreting them. In order to move to Option<>, we'd need to be confident that a field can only have 0 value when it's empty (and it won't change in the future). Please let me know what you think.

Copy link
Copy Markdown
Member

@jbaublitz jbaublitz left a comment

Choose a reason for hiding this comment

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

I 100% agree and have generally tended toward that approach throughout the library as you can probably see. Thanks for making the revisions. I'll approve and merge.

@jbaublitz jbaublitz moved this from In Progress to In Review in 2026April Apr 27, 2026
@jbaublitz jbaublitz merged commit 742c29f into stratis-storage:master Apr 27, 2026
44 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in 2026April Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

CryptKeyslotHandle::get_pbkdf() segfaults for type Argon2I/Argon2Id keyslots

3 participants