Remove no_verify feature flag in favor of cfg(target_arch)

This commit is contained in:
Michael Pfaff 2022-03-06 12:11:22 -05:00
parent 86ba5e1d6c
commit 3948597cd9
Signed by: michael
GPG Key ID: F1A27427218FCA77
3 changed files with 7 additions and 9 deletions

View File

@ -30,8 +30,6 @@ criterion = "0.3"
[features]
default = ["use_pem"]
use_pem = ["pem", "simple_asn1"]
no_verify = []
wasm = ["no_verify"]
[[bench]]
name = "jwt"

View File

@ -1,7 +1,7 @@
use serde::de::DeserializeOwned;
use crate::algorithms::AlgorithmFamily;
#[cfg(not(feature = "no_verify"))]
#[cfg(not(target_arch = "wasm32"))]
use crate::crypto::verify;
use crate::errors::{new_error, ErrorKind, Result};
use crate::header::Header;
@ -165,7 +165,10 @@ fn verify_signature<'a>(
}
}
#[cfg(not(target_arch = "wasm32"))]
let (signature, message) = expect_two!(token.rsplitn(2, '.'));
#[cfg(target_arch = "wasm32")]
let (_, message) = expect_two!(token.rsplitn(2, '.'));
let (payload, header) = expect_two!(message.rsplitn(2, '.'));
let header = Header::from_encoded(header)?;
@ -174,11 +177,11 @@ fn verify_signature<'a>(
}
if validation.validate_signature {
#[cfg(not(feature = "no_verify"))]
#[cfg(not(target_arch = "wasm32"))]
if !verify(signature, message.as_bytes(), key, header.alg)? {
return Err(new_error(ErrorKind::InvalidSignature));
}
#[cfg(feature = "no_verify")]
#[cfg(target_arch = "wasm32")]
return Err(new_error(ErrorKind::VerificationNotSupported));
}

View File

@ -79,8 +79,7 @@ pub enum ErrorKind {
/// Something unspecified went wrong with crypto
Crypto(::ring::error::Unspecified),
/// Verification is disabled by the feature flag `no_verify`.
#[cfg(feature = "no_verify")]
/// Verification is disabled because the target does not support it.
VerificationNotSupported,
}
@ -106,7 +105,6 @@ impl StdError for Error {
ErrorKind::Json(ref err) => Some(err.as_ref()),
ErrorKind::Utf8(ref err) => Some(err),
ErrorKind::Crypto(ref err) => Some(err),
#[cfg(feature = "no_verify")]
ErrorKind::VerificationNotSupported => None,
}
}
@ -134,7 +132,6 @@ impl fmt::Display for Error {
ErrorKind::Utf8(ref err) => write!(f, "UTF-8 error: {}", err),
ErrorKind::Crypto(ref err) => write!(f, "Crypto error: {}", err),
ErrorKind::Base64(ref err) => write!(f, "Base64 error: {}", err),
#[cfg(feature = "no_verify")]
ErrorKind::VerificationNotSupported => write!(f, "{:?}", self.0),
}
}