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

Upgrade base64 to 0.21 #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2018"
features = ["openssl"]

[dependencies]
base64 = "0.13"
base64 = "0.21"
crypto-common = "0.1"
digest = "0.10"
hmac = { version = "0.12", features = ["reset"] }
Expand Down
3 changes: 2 additions & 1 deletion src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ pub trait VerifyingAlgorithm {
fn verify_bytes(&self, header: &str, claims: &str, signature: &[u8]) -> Result<bool, Error>;

fn verify(&self, header: &str, claims: &str, signature: &str) -> Result<bool, Error> {
let signature_bytes = base64::decode_config(signature, base64::URL_SAFE_NO_PAD)?;
use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
let signature_bytes = BASE64_URL_SAFE_NO_PAD.decode(signature)?;
self.verify_bytes(header, claims, &*signature_bytes)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/algorithm/rust_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ where
}

fn sign(&self, header: &str, claims: &str) -> Result<String, Error> {
use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
let hmac = get_hmac_with_data(self, header, claims);
let mac_result = hmac.finalize();
let code = mac_result.into_bytes();
Ok(base64::encode_config(&code, base64::URL_SAFE_NO_PAD))
Ok(BASE64_URL_SAFE_NO_PAD.encode(&code))
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ pub trait ToBase64 {

impl<T: Serialize> ToBase64 for T {
fn to_base64(&self) -> Result<Cow<str>, Error> {
use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
let json_bytes = serde_json::to_vec(&self)?;
let encoded_json_bytes = base64::encode_config(&json_bytes, base64::URL_SAFE_NO_PAD);
let encoded_json_bytes = BASE64_URL_SAFE_NO_PAD.encode(&json_bytes);
Ok(Cow::Owned(encoded_json_bytes))
}
}
Expand All @@ -180,7 +181,8 @@ pub trait FromBase64: Sized {

impl<T: for<'de> Deserialize<'de> + Sized> FromBase64 for T {
fn from_base64<Input: ?Sized + AsRef<[u8]>>(raw: &Input) -> Result<Self, Error> {
let json_bytes = base64::decode_config(raw, base64::URL_SAFE_NO_PAD)?;
use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
let json_bytes = BASE64_URL_SAFE_NO_PAD.decode(raw)?;
Ok(serde_json::from_slice(&json_bytes)?)
}
}
Expand Down