Update base64 crate
This commit is contained in:
parent
07b6ee2a19
commit
8c492f1413
|
@ -1,10 +1,12 @@
|
|||
# Changelog
|
||||
|
||||
## 2.0.0 (unreleased)
|
||||
## 2.0.0 (2017-04-23)
|
||||
|
||||
- Use Serde instead of rustc_serialize
|
||||
- Add RSA support
|
||||
- Change API, see README for new usage
|
||||
- API overhaul, see README for new usage
|
||||
- Add validation
|
||||
- Update all dependencies
|
||||
|
||||
## Previous
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "jsonwebtoken"
|
||||
version = "2.0.0-beta-1"
|
||||
version = "2.0.0"
|
||||
authors = ["Vincent Prouillet <vincent@wearewizards.io>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
@ -15,6 +15,6 @@ serde_json = "1.0"
|
|||
serde_derive = "1.0"
|
||||
serde = "1.0"
|
||||
ring = { version = "0.7", features = ["rsa_signing", "dev_urandom_fallback"] }
|
||||
base64 = "0.4"
|
||||
base64 = "0.5"
|
||||
untrusted = "0.3"
|
||||
chrono = "0.3"
|
||||
|
|
|
@ -29,10 +29,11 @@ pub enum Algorithm {
|
|||
/// The actual HS signing + encoding
|
||||
fn sign_hmac(alg: &'static digest::Algorithm, key: &[u8], signing_input: &str) -> Result<String> {
|
||||
let signing_key = hmac::SigningKey::new(alg, key);
|
||||
Ok(base64::encode_config(
|
||||
hmac::sign(&signing_key, signing_input.as_bytes()).as_ref(),
|
||||
base64::URL_SAFE_NO_PAD
|
||||
))
|
||||
let digest = hmac::sign(&signing_key, signing_input.as_bytes());
|
||||
|
||||
Ok(
|
||||
base64::encode_config::<digest::Digest>(&digest, base64::URL_SAFE_NO_PAD)
|
||||
)
|
||||
}
|
||||
|
||||
/// The actual RSA signing + encoding
|
||||
|
@ -46,9 +47,8 @@ fn sign_rsa(alg: Algorithm, key: &[u8], signing_input: &str) -> Result<String> {
|
|||
};
|
||||
|
||||
let key_pair = Arc::new(
|
||||
signature::RSAKeyPair::from_der(
|
||||
untrusted::Input::from(key)
|
||||
).map_err(|_| ErrorKind::InvalidKey)?
|
||||
signature::RSAKeyPair::from_der(untrusted::Input::from(key))
|
||||
.map_err(|_| ErrorKind::InvalidKey)?
|
||||
);
|
||||
let mut signing_state = signature::RSASigningState::new(key_pair)
|
||||
.map_err(|_| ErrorKind::InvalidKey)?;
|
||||
|
@ -57,10 +57,9 @@ fn sign_rsa(alg: Algorithm, key: &[u8], signing_input: &str) -> Result<String> {
|
|||
signing_state.sign(ring_alg, &rng, signing_input.as_bytes(), &mut signature)
|
||||
.map_err(|_| ErrorKind::InvalidKey)?;
|
||||
|
||||
Ok(base64::encode_config(
|
||||
signature.as_ref(),
|
||||
base64::URL_SAFE_NO_PAD
|
||||
))
|
||||
Ok(
|
||||
base64::encode_config::<[u8]>(&signature, base64::URL_SAFE_NO_PAD)
|
||||
)
|
||||
}
|
||||
|
||||
/// Take the payload of a JWT, sign it using the algorithm given and return
|
||||
|
|
|
@ -61,7 +61,7 @@ error_chain! {
|
|||
|
||||
foreign_links {
|
||||
Unspecified(ring::error::Unspecified) #[doc = "An error happened while signing/verifying a token with RSA"];
|
||||
Base64(base64::Base64Error) #[doc = "An error happened while decoding some base64 text"];
|
||||
Base64(base64::DecodeError) #[doc = "An error happened while decoding some base64 text"];
|
||||
Json(serde_json::Error) #[doc = "An error happened while serializing/deserializing JSON"];
|
||||
Utf8(::std::string::FromUtf8Error) #[doc = "An error happened while trying to convert the result of base64 decoding to a String"];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue