Skip to content

Method to load urlsafe base64 hmac encoding key #3

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

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use base64::{engine::general_purpose::STANDARD, Engine};
use base64::{
engine::general_purpose::{STANDARD, URL_SAFE},
Engine,
};
use serde::ser::Serialize;

use crate::algorithms::AlgorithmFamily;
Expand Down Expand Up @@ -30,6 +33,12 @@ impl EncodingKey {
Ok(EncodingKey { family: AlgorithmFamily::Hmac, content: out })
}

/// For loading websafe base64 HMAC secrets, ex: ACME EAB credentials.
pub fn from_urlsafe_base64_secret(secret: &str) -> Result<Self> {
let out = URL_SAFE.decode(secret)?;
Ok(EncodingKey { family: AlgorithmFamily::Hmac, content: out })
}

/// If you are loading a RSA key from a .pem file.
/// This errors if the key is not a valid RSA key.
/// Only exists if the feature `use_pem` is enabled.
Expand Down