Skip to content

Commit

Permalink
clone-free serde Value deserialization (#178)
Browse files Browse the repository at this point in the history
* clone-free serde Value deserialization
  • Loading branch information
sabify authored and Keats committed Feb 2, 2022
1 parent 9fd9db5 commit d8cc36d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,15 @@ pub fn validate(claims: &Map<String, Value>, options: &Validation) -> Result<()>
if let Some(ref correct_aud) = options.aud {
if let Some(aud) = claims.get("aud") {
match aud {
Value::String(aud_found) => {
if !correct_aud.contains(aud_found) {
Value::String(aud) => {
if !correct_aud.contains(aud) {
return Err(new_error(ErrorKind::InvalidAudience));
}
}
Value::Array(_) => {
let provided_aud: HashSet<String> = from_value(aud.clone())?;
if provided_aud.intersection(correct_aud).next().is_none() {
use serde::Deserialize;
let aud = HashSet::<String>::deserialize(aud)?;
if aud.intersection(correct_aud).next().is_none() {
return Err(new_error(ErrorKind::InvalidAudience));
}
}
Expand Down

0 comments on commit d8cc36d

Please sign in to comment.