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

Get NonceSize from the algorithm #622

Closed
tisonkun opened this issue Aug 17, 2024 · 4 comments
Closed

Get NonceSize from the algorithm #622

tisonkun opened this issue Aug 17, 2024 · 4 comments

Comments

@tisonkun
Copy link

Is it reasonable to add a method nonce_size() to algorithms like Aes256Gcm?

Usage:

let nonce_size = Aes256Gcm::nonce_size();

To avoid inline magic numbers (12 in this case).

@tarcieri
Copy link
Member

Nonce size is available as AeadCore::NonceSize.

The typenum::Unsigned::USIZE associated constant in particular can be used to query it as a usize.

@tisonkun
Copy link
Author

@tarcieri Yeah. I can see the NonceSize associated type. In what syntax I can get the size from the Aes256Gcm type or an instant of it?

@tarcieri
Copy link
Member

<Aes256Gcm as AeadCore>::NonceSize::USIZE

@tisonkun
Copy link
Author

@tarcieri Thank you! Works perfectly:

use aes_gcm::aead::Aead;
use aes_gcm::aes::cipher::Unsigned;
use aes_gcm::AeadCore;

let nonce_size = <aes_gcm::Aes256Gcm as AeadCore>::NonceSize::USIZE;

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