Skip to content

Commit

Permalink
Merge pull request #1298 from NickeZ/nickez/ci-rustfmt
Browse files Browse the repository at this point in the history
Nickez/ci rustfmt
  • Loading branch information
NickeZ authored Sep 20, 2024
2 parents 255ed44 + 8b24509 commit f2acf2e
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 150 deletions.
7 changes: 7 additions & 0 deletions .ci/check-style
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -e
set -o pipefail

CLANGFORMAT=${CLANGFORMAT:-clang-format-18}
RUSTFMT=${RUSTFMT:-rustfmt}

command -v git >/dev/null 2>&1 || { echo >&2 "git is missing"; exit 1; }
command -v xargs >/dev/null 2>&1 || { echo >&2 "xargs is missing"; exit 1; }
Expand Down Expand Up @@ -37,3 +38,9 @@ if git --no-pager diff --diff-filter=d --name-only ${TARGET_BRANCH} HEAD | grep
git --no-pager diff
exit 1
fi

RUST_SOURCES=$(git --no-pager diff --diff-filter=d --name-only ${TARGET_BRANCH} HEAD | grep -E "^src/rust.*\.rs\$" | grep -v -E "^src/rust/vendor" || true)
if [ -n "$RUST_SOURCES" ] ; then
echo $RUST_SOURCES
"$RUSTFMT" --check $RUST_SOURCES
fi
2 changes: 1 addition & 1 deletion .ci/ci
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -e
# Deny warnings in rust. CI will fail to compile any code with warnings in it.
export RUSTFLAGS="-Dwarnings"

# Check style for C
# Check style for C and Rust
./.ci/check-style

# Check that we can generate protobuf definitions for python
Expand Down
9 changes: 6 additions & 3 deletions src/rust/bitbox02-rust/src/hww/api/ethereum/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ pub fn from_pubkey_hash(recipient: &[u8; 20], address_case: pb::EthAddressCase)
// valid utf8 because hex and the uppercasing above is correct.
core::str::from_utf8_unchecked(&hex[..])
})
},
}
pb::EthAddressCase::Upper => {
format!("0x{}", hex::encode_upper(recipient))
},
}
pb::EthAddressCase::Lower => {
format!("0x{}", hex::encode(recipient))
}
Expand All @@ -58,7 +58,10 @@ pub fn from_pubkey_hash(recipient: &[u8; 20], address_case: pb::EthAddressCase)
/// `recipient` - 20 byte tail (last 20 bytes of the pubkeyhash).
pub fn from_pubkey(pubkey_uncompressed: &[u8; 65]) -> String {
let hash = sha3::Keccak256::digest(&pubkey_uncompressed[1..]);
from_pubkey_hash(hash[hash.len() - 20..].try_into().unwrap(), pb::EthAddressCase::Mixed)
from_pubkey_hash(
hash[hash.len() - 20..].try_into().unwrap(),
pb::EthAddressCase::Mixed,
)
}

#[cfg(test)]
Expand Down
6 changes: 4 additions & 2 deletions src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ impl<'a> Transaction<'a> {
fn case(&self) -> Result<pb::EthAddressCase, Error> {
match self {
Transaction::Legacy(legacy) => Ok(pb::EthAddressCase::try_from(legacy.address_case)?),
Transaction::Eip1559(eip1559) => Ok(pb::EthAddressCase::try_from(eip1559.address_case)?),
Transaction::Eip1559(eip1559) => {
Ok(pb::EthAddressCase::try_from(eip1559.address_case)?)
}
}
}
}
Expand Down Expand Up @@ -268,7 +270,7 @@ async fn verify_standard_transaction(
})
.await?;
}

let address = super::address::from_pubkey_hash(&recipient, request.case()?);
let amount = Amount {
unit: params.unit,
Expand Down
5 changes: 2 additions & 3 deletions src/rust/bitbox02-rust/src/hww/api/sdcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ pub async fn process(
) -> Result<Response, Error> {
let inserted = bitbox02::sd::sdcard_inserted();
match SdCardAction::try_from(action) {
Ok(SdCardAction::InsertCard) => {},
Ok(SdCardAction::InsertCard) => {}
_ => return Ok(Response::Success(pb::Success {})),
};
if inserted
{
if inserted {
return Ok(Response::Success(pb::Success {}));
}
sdcard::sdcard().await?;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/bitbox02-rust/src/workflow/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,4 @@ mod tests {
&bruteforce_lastword(&mnemonic)
);
}
}
}
9 changes: 3 additions & 6 deletions src/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ pub async fn get() -> Result<zeroize::Zeroizing<String>, CancelError> {
let words = "boring mistake dish oyster truth pigeon viable emerge sort crash wire portion cannon couple enact box walk height pull today solid off enable tide";
bitbox02::println_stdout("Restored from recovery words below:");
bitbox02::println_stdout(words);

Ok(zeroize::Zeroizing::new(
words
.to_string()
))
}

Ok(zeroize::Zeroizing::new(words.to_string()))
}
Loading

0 comments on commit f2acf2e

Please sign in to comment.