diff options
author | Luca Casonato <hello@lcas.dev> | 2023-10-26 18:39:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-26 18:39:04 +0200 |
commit | 08b99f39093ef8f0363bf943ab6719ed0f9d7b21 (patch) | |
tree | f8db043351b6bc94a189c5f00ed6f606aa330df5 /ext/crypto/import_key.rs | |
parent | 842e29057d6e545c6b498c584a5366fff34f6aa7 (diff) |
chore: update base64 crate (#20877)
Diffstat (limited to 'ext/crypto/import_key.rs')
-rw-r--r-- | ext/crypto/import_key.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/ext/crypto/import_key.rs b/ext/crypto/import_key.rs index b2d5cdc4f..0a864d68c 100644 --- a/ext/crypto/import_key.rs +++ b/ext/crypto/import_key.rs @@ -1,5 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use base64::Engine; use deno_core::error::AnyError; use deno_core::op2; use deno_core::JsBuffer; @@ -106,12 +107,19 @@ pub fn op_crypto_import_key( } } -const URL_SAFE_FORGIVING: base64::Config = - base64::URL_SAFE_NO_PAD.decode_allow_trailing_bits(true); +const BASE64_URL_SAFE_FORGIVING: + base64::engine::general_purpose::GeneralPurpose = + base64::engine::general_purpose::GeneralPurpose::new( + &base64::alphabet::URL_SAFE, + base64::engine::general_purpose::GeneralPurposeConfig::new() + .with_decode_allow_trailing_bits(true) + .with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent), + ); macro_rules! jwt_b64_int_or_err { ($name:ident, $b64:expr, $err:expr) => { - let bytes = base64::decode_config($b64, URL_SAFE_FORGIVING) + let bytes = BASE64_URL_SAFE_FORGIVING + .decode($b64) .map_err(|_| data_error($err))?; let $name = UIntRef::new(&bytes).map_err(|_| data_error($err))?; }; @@ -759,7 +767,8 @@ fn import_key_ec( fn import_key_aes(key_data: KeyData) -> Result<ImportKeyResult, AnyError> { Ok(match key_data { KeyData::JwkSecret { k } => { - let data = base64::decode_config(k, URL_SAFE_FORGIVING) + let data = BASE64_URL_SAFE_FORGIVING + .decode(k) .map_err(|_| data_error("invalid key data"))?; ImportKeyResult::Hmac { raw_data: RustRawKeyData::Secret(data.into()), @@ -772,7 +781,8 @@ fn import_key_aes(key_data: KeyData) -> Result<ImportKeyResult, AnyError> { fn import_key_hmac(key_data: KeyData) -> Result<ImportKeyResult, AnyError> { Ok(match key_data { KeyData::JwkSecret { k } => { - let data = base64::decode_config(k, URL_SAFE_FORGIVING) + let data = BASE64_URL_SAFE_FORGIVING + .decode(k) .map_err(|_| data_error("invalid key data"))?; ImportKeyResult::Hmac { raw_data: RustRawKeyData::Secret(data.into()), |