From 87ad2283a135d66db07f0464a4387c06dff57967 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 13 Mar 2023 21:51:59 -0600 Subject: [PATCH] argon2: add `ParamsBuilder::context` Shortcut for creating an `Argon2` context from `ParamsBuilder` --- argon2/src/params.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/argon2/src/params.rs b/argon2/src/params.rs index fdb538dc..9bfb5a28 100644 --- a/argon2/src/params.rs +++ b/argon2/src/params.rs @@ -1,6 +1,6 @@ //! Argon2 password hash parameters. -use crate::{Error, Result, SYNC_POINTS}; +use crate::{Algorithm, Argon2, Error, Result, Version, SYNC_POINTS}; use base64ct::{Base64Unpadded as B64, Encoding}; use core::str::FromStr; @@ -471,6 +471,11 @@ impl ParamsBuilder { Ok(params) } + + /// Create a new [`Argon2`] context using the provided algorithm/version. + pub fn context(&self, algorithm: Algorithm, version: Version) -> Result> { + Ok(Argon2::new(algorithm, version, self.build()?)) + } } impl Default for ParamsBuilder {