Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aes-gcm: Make key_size() a const fn #649

Closed
ChocolateLoverRaj opened this issue Dec 27, 2024 · 2 comments
Closed

aes-gcm: Make key_size() a const fn #649

ChocolateLoverRaj opened this issue Dec 27, 2024 · 2 comments

Comments

@ChocolateLoverRaj
Copy link

I am trying to use key_size like this:

#[derive(Debug, Serialize, Deserialize)]
struct EncryptionData {
    password_derived_key_salt: [u8; Salt::RECOMMENDED_LENGTH],
    password_derived_key: [u8; Aes256Gcm::key_size()],
}

But that isn't currently possible:

cannot call non-const fn `<AesGcm<aes_gcm::aes::Aes256, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>> as KeySizeUser>::key_size` in constants
calls in constants are limited to constant functions, tuple structs and tuple variants

It seems like key_size could be made const just by adding const to it.

@newpavlov
Copy link
Member

newpavlov commented Dec 27, 2024

Trait methods can not be currently made const on stable Rust. You should import the aead::generic_array::typenum::Unsigned trait and use Aes256Gcm::KeySize::USIZE.

@ChocolateLoverRaj
Copy link
Author

I was using nightly a lot recently so I didn't realize. I will use the trait.

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

No branches or pull requests

2 participants