Skip to content

Commit

Permalink
Fix findings after clippy update (#1365)
Browse files Browse the repository at this point in the history
* fix clippy findings

* fix formatting

* refactor .clone_into calls into .to_string

* fix previous edit

* disable empty_docs for wasm binding for now

* fix missing newline

* disable self update from rust setup in ci for now

* update self update skip to skip only for windows build
  • Loading branch information
wulfraem authored May 13, 2024
1 parent 51aedd5 commit 149bfac
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 27 deletions.
19 changes: 17 additions & 2 deletions .github/actions/rust/rust-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ runs:
shell: bash
run: |
if ! rustup self update; then
# self update is currently broken on Windows runners:
# https://github.com/rust-lang/rustup/issues/3709
# so we'll skip self update for windows
OS=${{ inputs.os }}
IS_WINDOWS=false; [[ $OS =~ ^[wW]indows ]] && IS_WINDOWS=true
if [[ $IS_WINDOWS = true ]] ;
then
echo "skipping self update on windows runner due to https://github.com/rust-lang/rustup/issues/3709"
elif ! rustup self update; then
echo "rustup self update failed"
fi
Expand All @@ -57,7 +66,13 @@ runs:
rustup target add $TARGET
fi
rustup update
if [[ $IS_WINDOWS = true ]] ;
then
echo "skipping self update on windows runner due to https://github.com/rust-lang/rustup/issues/3709"
rustup update --no-self-update
else
rustup update
fi
TOOLCHAIN=${{ inputs.toolchain }}
if [[ $TOOLCHAIN != 'stable' ]]; then
Expand Down
5 changes: 5 additions & 0 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ instant = { version = "0.1", default-features = false, features = ["wasm-bindgen
[profile.release]
opt-level = 's'
lto = true

[lints.clippy]
# can be removed as soon as fix has been added to clippy
# see https://github.com/rust-lang/rust-clippy/issues/12377
empty_docs = "allow"
4 changes: 2 additions & 2 deletions identity_credential/src/credential/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod tests {
assert_eq!(proof.type_, "test-proof");
let value = proof
.properties
.get(&"signature".to_owned())
.get("signature")
.expect("property in proof doesn't exist");
assert_eq!(value, "abc123");
}
Expand Down Expand Up @@ -88,7 +88,7 @@ mod tests {
assert_eq!(proof.type_, "RsaSignature2018");
let value = proof
.properties
.get(&"proofPurpose".to_owned())
.get("proofPurpose")
.expect("property in proof doesn't exist");
assert_eq!(value, "assertionMethod");
assert_eq!(proof.properties.len(), 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ 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() != Some(CREDENTIAL_SUBJECT_TYPE) {
return Err(StatusList2021CredentialError::InvalidProperty("credentialSubject.type"));
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion identity_credential/src/validator/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn encode_public_ed25519_jwk(public_key: &PublicKey) -> Jwk {
let mut params = JwkParamsOkp::new();
params.x = x;
params.d = None;
params.crv = EdCurve::Ed25519.name().to_owned();
params.crv = EdCurve::Ed25519.name().to_string();
let mut jwk = Jwk::from_params(params);
jwk.set_alg(JwsAlgorithm::EdDSA.name());
jwk
Expand Down
2 changes: 1 addition & 1 deletion identity_iota_core/src/document/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn encode_public_ed25519_jwk(public_key: &[u8]) -> Jwk {
let mut params = JwkParamsOkp::new();
params.x = x;
params.d = None;
params.crv = EdCurve::Ed25519.name().to_owned();
params.crv = EdCurve::Ed25519.name().to_string();
let mut jwk = Jwk::from_params(params);
jwk.set_alg(JwsAlgorithm::EdDSA.name());
jwk
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 @@ -103,6 +103,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 @@ -238,6 +244,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 @@ -320,6 +332,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 @@ -369,6 +387,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
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();
params.crv = EdCurve::Ed25519.name().to_string();
Jwk::from_params(params)
}
8 changes: 4 additions & 4 deletions identity_storage/src/key_storage/memstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ mod tests {
let store: JwkMemStore = JwkMemStore::new();

let mut ec_params = JwkParamsEc::new();
ec_params.crv = EcCurve::P256.name().to_owned();
ec_params.x = "".to_owned();
ec_params.y = "".to_owned();
ec_params.d = Some("".to_owned());
ec_params.crv = EcCurve::P256.name().to_string();
ec_params.x = String::new();
ec_params.y = String::new();
ec_params.d = Some(String::new());
let jwk_ec = Jwk::from_params(ec_params);

let err = store.insert(jwk_ec).await.unwrap_err();
Expand Down
8 changes: 4 additions & 4 deletions identity_storage/src/key_storage/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ pub(crate) async fn test_incompatible_key_alg(store: impl JwkStorage) {

pub(crate) async fn test_incompatible_key_type(store: impl JwkStorage) {
let mut ec_params = JwkParamsEc::new();
ec_params.crv = EcCurve::P256.name().to_owned();
ec_params.x = "".to_owned();
ec_params.y = "".to_owned();
ec_params.d = Some("".to_owned());
ec_params.crv = EcCurve::P256.name().to_string();
ec_params.x = String::new();
ec_params.y = String::new();
ec_params.d = Some(String::new());
let jwk_ec = Jwk::from_params(ec_params);

let err = store.insert(jwk_ec).await.unwrap_err();
Expand Down
2 changes: 1 addition & 1 deletion identity_storage/src/storage/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub(crate) fn encode_public_ed25519_jwk(public_key: &PublicKey) -> Jwk {
let mut params = JwkParamsOkp::new();
params.x = x;
params.d = None;
params.crv = EdCurve::Ed25519.name().to_owned();
params.crv = EdCurve::Ed25519.name().to_string();
let mut jwk = Jwk::from_params(params);
jwk.set_alg(JwsAlgorithm::EdDSA.name());
jwk
Expand Down
2 changes: 1 addition & 1 deletion identity_stronghold/src/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();
params.crv = EdCurve::Ed25519.name().to_string();
Jwk::from_params(params)
}
4 changes: 2 additions & 2 deletions identity_stronghold/src/stronghold_jwk_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl StrongholdStorage {

let mut params = JwkParamsOkp::new();
params.x = jwu::encode_b64(public_key);
params.crv = EdCurve::Ed25519.name().to_owned();
params.crv = EdCurve::Ed25519.name().to_string();
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 @@ -148,7 +148,7 @@ impl JwkStorage for StrongholdStorage {

let mut params = JwkParamsOkp::new();
params.x = jwu::encode_b64(public_key);
params.crv = EdCurve::Ed25519.name().to_owned();
params.crv = EdCurve::Ed25519.name().to_string();
let mut jwk: Jwk = Jwk::from_params(params);
jwk.set_alg(alg.name());
jwk.set_kid(jwk.thumbprint_sha256_b64());
Expand Down
8 changes: 4 additions & 4 deletions identity_stronghold/src/tests/test_jwk_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ mod jwk_storage_tests {

pub(crate) async fn test_incompatible_key_type(store: impl JwkStorage) {
let mut ec_params = JwkParamsEc::new();
ec_params.crv = EcCurve::P256.name().to_owned();
ec_params.x = "".to_owned();
ec_params.y = "".to_owned();
ec_params.d = Some("".to_owned());
ec_params.crv = EcCurve::P256.name().to_string();
ec_params.x = String::new();
ec_params.y = String::new();
ec_params.d = Some(String::new());
let jwk_ec = Jwk::from_params(ec_params);

let err = store.insert(jwk_ec).await.unwrap_err();
Expand Down
2 changes: 1 addition & 1 deletion identity_stronghold/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) fn encode_public_ed25519_jwk(public_key: &PublicKey) -> Jwk {
let mut params = JwkParamsOkp::new();
params.x = x;
params.d = None;
params.crv = EdCurve::Ed25519.name().to_owned();
params.crv = EdCurve::Ed25519.name().to_string();
let mut jwk = Jwk::from_params(params);
jwk.set_alg(JwsAlgorithm::EdDSA.name());
jwk
Expand Down

0 comments on commit 149bfac

Please sign in to comment.