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

Update dependencies #13

Open
wants to merge 5 commits 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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ license = "MIT"
edition = "2021"

[dependencies]
base64 = "0.13"
bitflags = "1.2"
base64 = "0.21"
bitflags = "2.4"
generic-array = "0.14"
jsonwebtoken = { version = "8.0", optional = true }
jsonwebtoken = { version = "9.0", optional = true }
num-bigint = { version = "0.4", optional = true }
p256 = { version = "0.10", optional = true, features = ["arithmetic"] }
p256 = { version = "0.13", optional = true, features = ["arithmetic"] }
rand = { version = "0.8", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -31,7 +31,7 @@ generate = ["p256", "rand"]
thumbprint = ["sha2"]

[dev-dependencies]
jsonwebtoken = "8.0"
jsonwebtoken = "9.0"

[package.metadata.docs.rs]
all-features = true
2 changes: 1 addition & 1 deletion src/key_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{
macro_rules! impl_key_ops {
($(($key_op:ident, $const_name:ident, $i:literal)),+,) => {
bitflags::bitflags! {
#[derive(Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct KeyOps: u16 {
$(const $const_name = $i;)*
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl JsonWebKey {
}

pub fn set_algorithm(&mut self, alg: Algorithm) -> Result<(), Error> {
Self::validate_algorithm(alg, &*self.key)?;
Self::validate_algorithm(alg, &self.key)?;
self.algorithm = Some(alg);
Ok(())
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl std::str::FromStr for JsonWebKey {
Some(alg) => alg,
None => return Ok(jwk),
};
Self::validate_algorithm(alg, &*jwk.key).map(|_| jwk)
Self::validate_algorithm(alg, &jwk.key).map(|_| jwk)
}
}

Expand Down Expand Up @@ -337,7 +337,7 @@ impl Key {
Some(private_point) => {
pkcs8::write_private(oids, |writer: &mut DERWriterSeq<'_>| {
writer.next().write_i8(1); // version
writer.next().write_bytes(&**private_point);
writer.next().write_bytes(private_point);
// The following tagged value is optional. OpenSSL produces it,
// but many tools, including jwt.io and `jsonwebtoken`, don't like it,
// so we don't include it.
Expand Down Expand Up @@ -411,8 +411,9 @@ impl Key {
/// If this key is asymmetric, encodes it as PKCS#8 with PEM armoring.
#[cfg(feature = "pkcs-convert")]
pub fn try_to_pem(&self) -> Result<String, ConversionError> {
use base64::{engine::general_purpose::STANDARD, Engine};
use std::fmt::Write;
let der_b64 = base64::encode(self.try_to_der()?);
let der_b64 = STANDARD.encode(self.try_to_der()?);
let key_ty = if self.is_private() {
"PRIVATE"
} else {
Expand Down
13 changes: 9 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use base64::{
alphabet::URL_SAFE,
engine::{general_purpose::NO_PAD, GeneralPurpose},
Engine,
};
use serde::{
de::{self, Deserialize, Deserializer},
ser::{Serialize, Serializer},
};
use zeroize::Zeroizing;

fn base64_config() -> base64::Config {
base64::Config::new(base64::CharacterSet::UrlSafe, false /* pad */)
fn base64_config() -> GeneralPurpose {
GeneralPurpose::new(&URL_SAFE, NO_PAD)
}

pub(crate) fn base64_encode(bytes: impl AsRef<[u8]>) -> String {
base64::encode_config(bytes, base64_config())
base64_config().encode(bytes)
}

fn base64_decode(b64: impl AsRef<[u8]>) -> Result<Vec<u8>, base64::DecodeError> {
base64::decode_config(b64, base64_config())
base64_config().decode(b64)
}

pub(crate) mod serde_base64 {
Expand Down