Skip to content

Commit

Permalink
revert last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
UMR1352 committed May 8, 2024
1 parent 5135f0b commit 63df8d4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ impl StatusList2021CredentialSubject {
return Err(StatusList2021CredentialError::MultipleCredentialSubject);
};
if let Some(subject_type) = subject.properties.get("type") {
if !subject_type.as_str().is_some_and(|t| t == CREDENTIAL_SUBJECT_TYPE) {
if !subject_type
.as_str()
.map(|t| t == CREDENTIAL_SUBJECT_TYPE)
.unwrap_or(false)
{
return Err(StatusList2021CredentialError::InvalidProperty("credentialSubject.type"));
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions identity_jose/src/jwk/key_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ pub struct JwkParamsEc {
pub d: Option<String>, // ECC Private Key
}

impl Default for JwkParamsEc {
fn default() -> Self {
Self::new()
}
}

impl JwkParamsEc {
/// Creates new JWK EC Params.
pub const fn new() -> Self {
Expand Down Expand Up @@ -251,6 +257,12 @@ pub struct JwkParamsRsaPrime {
pub t: String, // Factor CRT Coefficient
}

impl Default for JwkParamsRsa {
fn default() -> Self {
Self::new()
}
}

impl JwkParamsRsa {
/// Creates new JWK RSA Params.
pub const fn new() -> Self {
Expand Down Expand Up @@ -333,6 +345,12 @@ pub struct JwkParamsOct {
pub k: String, // Key Value
}

impl Default for JwkParamsOct {
fn default() -> Self {
Self::new()
}
}

impl JwkParamsOct {
/// Creates new JWK Oct Params.
pub const fn new() -> Self {
Expand Down Expand Up @@ -382,6 +400,12 @@ pub struct JwkParamsOkp {
pub d: Option<String>, // Private Key
}

impl Default for JwkParamsOkp {
fn default() -> Self {
Self::new()
}
}

impl JwkParamsOkp {
/// Creates new JWK OKP Params.
pub const fn new() -> Self {
Expand Down
6 changes: 6 additions & 0 deletions identity_jose/src/jwt/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ pub struct JwtHeader {
nonce: Option<String>,
}

impl Default for JwtHeader {
fn default() -> Self {
Self::new()
}
}

impl JwtHeader {
/// Create a new `JwtHeader`.
pub const fn new() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions identity_jose/src/jwu/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pub(crate) fn parse_utf8(slice: &(impl AsRef<[u8]> + ?Sized)) -> Result<&str> {
str::from_utf8(slice.as_ref()).map_err(Error::InvalidUtf8)
}

pub(crate) fn filter_non_empty_bytes<'a, T, U: 'a>(value: T) -> Option<&'a [u8]>
pub(crate) fn filter_non_empty_bytes<'a, T, U>(value: T) -> Option<&'a [u8]>
where
T: Into<Option<&'a U>>,
U: AsRef<[u8]> + ?Sized,
U: AsRef<[u8]> + ?Sized + 'a,
{
value.into().map(AsRef::as_ref).filter(|value| !value.is_empty())
}
Expand Down
7 changes: 6 additions & 1 deletion identity_storage/src/key_storage/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ pub fn expand_bls_jwk(jwk: &Jwk) -> KeyStorageResult<(Option<BBSplusSecretKey>,
let params = jwk
.try_ec_params()
.ok()
.filter(|params| params.try_bls_curve().is_ok_and(|curve| curve == BlsCurve::BLS12381G2))
.filter(|params| {
params
.try_bls_curve()
.map(|curve| curve == BlsCurve::BLS12381G2)
.unwrap_or(false)
})
.context(format!("not a {} curve key", BlsCurve::BLS12381G2))
.map_err(|e| KeyStorageError::new(KeyStorageErrorKind::UnsupportedKeyType).with_source(e))?;

Expand Down
2 changes: 1 addition & 1 deletion identity_storage/src/key_storage/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ pub(crate) fn encode_jwk(private_key: &SecretKey, public_key: &crypto::signature
let mut params = JwkParamsOkp::new();
params.x = x;
params.d = Some(d);
params.crv = EdCurve::Ed25519.name().to_owned();
EdCurve::Ed25519.name().clone_into(&mut params.crv);
Jwk::from_params(params)
}
6 changes: 4 additions & 2 deletions identity_storage/src/key_storage/memstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ mod bbs_plus_impl {
// Check the provided JWK represents a BLS12381G2 key.
if !public_key
.try_ec_params()
.is_ok_and(|ec| ec.crv == BlsCurve::BLS12381G2.to_string())
.map(|ec| ec.crv == BlsCurve::BLS12381G2.to_string())
.unwrap_or(false)
{
return Err(
KeyStorageError::new(KeyStorageErrorKind::UnsupportedKeyType)
Expand Down Expand Up @@ -401,7 +402,8 @@ mod bbs_plus_impl {
// Check the provided JWK represents a BLS12381G2 key.
if !public_key
.try_ec_params()
.is_ok_and(|ec| ec.crv == BlsCurve::BLS12381G2.to_string())
.map(|ec| ec.crv == BlsCurve::BLS12381G2.to_string())
.unwrap_or(false)
{
return Err(
KeyStorageError::new(KeyStorageErrorKind::UnsupportedKeyType)
Expand Down
4 changes: 2 additions & 2 deletions identity_stronghold/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl StrongholdStorage {

let mut params = JwkParamsOkp::new();
params.x = jwu::encode_b64(public_key);
params.crv = EdCurve::Ed25519.name().to_owned();
EdCurve::Ed25519.name().clone_into(&mut params.crv);
let mut jwk: Jwk = Jwk::from_params(params);
jwk.set_alg(JwsAlgorithm::EdDSA.name());
jwk.set_kid(jwk.thumbprint_sha256_b64());
Expand Down Expand Up @@ -153,7 +153,7 @@ impl StrongholdStorage {

let mut params = JwkParamsOkp::new();
params.x = jwu::encode_b64(public_key);
params.crv = EdCurve::Ed25519.name().to_owned();
EdCurve::Ed25519.name().clone_into(&mut params.crv);
let mut jwk: Jwk = Jwk::from_params(params);
jwk.set_alg(JwsAlgorithm::EdDSA.name());
jwk.set_kid(jwk.thumbprint_sha256_b64());
Expand Down
2 changes: 1 addition & 1 deletion identity_stronghold/src/storage/stronghold_jwk_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl JwkStorage for StrongholdStorage {

let mut params = JwkParamsOkp::new();
params.x = jwu::encode_b64(public_key);
params.crv = EdCurve::Ed25519.name().to_owned();
EdCurve::Ed25519.name().clone_into(&mut params.crv);
let mut jwk: Jwk = Jwk::from_params(params);
jwk.set_alg(alg.name());
jwk.set_kid(jwk.thumbprint_sha256_b64());
Expand Down

0 comments on commit 63df8d4

Please sign in to comment.