Skip to content

Commit

Permalink
improve homogeinity check
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed May 17, 2024
1 parent 681d64d commit 42b35e2
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,17 @@ impl CoordinatePublicKey {
}

pub fn assert_homogeneity(subkeys: &[&Self]) -> Result<(), Error> {
subkeys.iter().map(|cpk| cpk.is_hybridized()).try_fold(
subkeys[0].is_hybridized(),
|acc, b| -> Result<bool, Error> {
if b != acc {
Err(Error::OperationNotPermitted(
"classic and hybridized access policies cannot be mixed".to_string(),
))
} else {
Ok(acc)
}
},
)?;
Ok(())
let is_homogeneous = subkeys
.iter()
.all(|cpk| cpk.is_hybridized() == subkeys[0].is_hybridized());

if is_homogeneous {
Ok(())
} else {
Err(Error::OperationNotPermitted(
"classic and hybridized access policies cannot be mixed".to_string(),
))
}
}
}

Expand Down

0 comments on commit 42b35e2

Please sign in to comment.