Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint fixes for new lints in cargo 1.75 #293

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 66 additions & 66 deletions chain/rust/src/byron/base58.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,72 +36,6 @@ pub fn decode(input: &str) -> Result<Vec<u8>> {
// base_decode(ALPHABET, input)
//}

#[cfg(test)]
mod tests {
fn encode(input: &[u8], expected: &str) {
let encoded = super::encode(input);
assert_eq!(encoded, expected);
}
fn decode(expected: &[u8], input: &str) {
let decoded = super::decode(input).unwrap();
assert_eq!(decoded.as_slice(), expected);
}

#[test]
fn test_vector_1() {
encode(b"\0\0\0\0", "11111");
decode(b"\0\0\0\0", "11111");
}

#[test]
fn test_vector_2() {
encode(b"This is awesome!", "BRY7dK2V98Sgi7CFWiZbap");
decode(b"This is awesome!", "BRY7dK2V98Sgi7CFWiZbap");
}

#[test]
fn test_vector_3() {
encode(b"Hello World...", "TcgsE5dzphUWfjcb9i5");
decode(b"Hello World...", "TcgsE5dzphUWfjcb9i5");
}

#[test]
fn test_vector_4() {
encode(b"\0abc", "1ZiCa");
decode(b"\0abc", "1ZiCa");
}

#[test]
fn test_vector_5() {
encode(b"\0\0abc", "11ZiCa");
decode(b"\0\0abc", "11ZiCa");
}

#[test]
fn test_vector_6() {
encode(b"\0\0\0abc", "111ZiCa");
decode(b"\0\0\0abc", "111ZiCa");
}

#[test]
fn test_vector_7() {
encode(b"\0\0\0\0abc", "1111ZiCa");
decode(b"\0\0\0\0abc", "1111ZiCa");
}

#[test]
fn test_vector_8() {
encode(
b"abcdefghijklmnopqrstuvwxyz",
"3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f",
);
decode(
b"abcdefghijklmnopqrstuvwxyz",
"3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f",
);
}
}

fn base_encode(alphabet_s: &str, input: &[u8]) -> Vec<u8> {
let alphabet = alphabet_s.as_bytes();
let base = alphabet.len() as u32;
Expand Down Expand Up @@ -171,3 +105,69 @@ fn base_decode(alphabet_s: &str, input: &[u8]) -> Result<Vec<u8>> {
bytes.reverse();
Ok(bytes)
}

#[cfg(test)]
mod tests {
fn encode(input: &[u8], expected: &str) {
let encoded = super::encode(input);
assert_eq!(encoded, expected);
}
fn decode(expected: &[u8], input: &str) {
let decoded = super::decode(input).unwrap();
assert_eq!(decoded.as_slice(), expected);
}

#[test]
fn test_vector_1() {
encode(b"\0\0\0\0", "11111");
decode(b"\0\0\0\0", "11111");
}

#[test]
fn test_vector_2() {
encode(b"This is awesome!", "BRY7dK2V98Sgi7CFWiZbap");
decode(b"This is awesome!", "BRY7dK2V98Sgi7CFWiZbap");
}

#[test]
fn test_vector_3() {
encode(b"Hello World...", "TcgsE5dzphUWfjcb9i5");
decode(b"Hello World...", "TcgsE5dzphUWfjcb9i5");
}

#[test]
fn test_vector_4() {
encode(b"\0abc", "1ZiCa");
decode(b"\0abc", "1ZiCa");
}

#[test]
fn test_vector_5() {
encode(b"\0\0abc", "11ZiCa");
decode(b"\0\0abc", "11ZiCa");
}

#[test]
fn test_vector_6() {
encode(b"\0\0\0abc", "111ZiCa");
decode(b"\0\0\0abc", "111ZiCa");
}

#[test]
fn test_vector_7() {
encode(b"\0\0\0\0abc", "1111ZiCa");
decode(b"\0\0\0\0abc", "1111ZiCa");
}

#[test]
fn test_vector_8() {
encode(
b"abcdefghijklmnopqrstuvwxyz",
"3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f",
);
decode(
b"abcdefghijklmnopqrstuvwxyz",
"3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f",
);
}
}
7 changes: 2 additions & 5 deletions chain/rust/src/byron/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use cml_crypto::{
impl_hash_type, Bip32PrivateKey, Bip32PublicKey, CryptoError, Ed25519Signature,
LegacyDaedalusPrivateKey, PublicKey, RawBytesEncoding, TransactionHash,
};
use std::{
convert::{TryFrom, TryInto},
fmt,
};
use std::{convert::TryFrom, fmt};

#[derive(Debug, thiserror::Error)]
pub enum ByronAddressError {
Expand All @@ -40,7 +37,7 @@ impl StakeholderId {
let buf = cbor!(pubk.0.as_ref()).unwrap();

let hash = Sha3_256::new(&buf);
StakeholderId(Blake2b224::new(hash.as_ref()).try_into().unwrap())
StakeholderId(Blake2b224::new(hash.as_ref()).into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion chain/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// possibly impacting PartialOrd performance on top of being unnecessary and occuring in generated code.
// Possibly the derivative crate could get updated to suppress this lint
// from within their proc macros itself. Issue: https://github.com/mcarton/rust-derivative/issues/115
#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
#![allow(clippy::non_canonical_partial_ord_impl)]

pub mod address;
pub mod assets;
Expand Down
1 change: 0 additions & 1 deletion cip25/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub use cml_core::{
metadata::{Metadata, TransactionMetadatum},
serialization::*,
};
pub use cml_core::{error::*, serialization::*};
use cml_crypto::RawBytesEncoding;
use std::io::{BufRead, Seek, SeekFrom, Write};

Expand Down
2 changes: 1 addition & 1 deletion core/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// possibly impacting PartialOrd performance on top of being unnecessary and occuring in generated code.
// Possibly the derivative crate could get updated to suppress this lint
// from within their proc macros itself. Issue: https://github.com/mcarton/rust-derivative/issues/115
#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
#![allow(clippy::non_canonical_partial_ord_impl)]

pub use error::*;

Expand Down
74 changes: 37 additions & 37 deletions crypto/rust/src/chain_crypto/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,43 +215,6 @@ impl<T, A: VerificationAlgorithm> std::cmp::PartialEq<Self> for Signature<T, A>

impl<T, A: VerificationAlgorithm> std::cmp::Eq for Signature<T, A> {}

#[cfg(test)]
pub(crate) mod test {
use super::*;
use crate::chain_crypto::key::{AsymmetricKey, KeyPair};

pub(crate) fn keypair_signing_ok<A: AsymmetricKey + SigningAlgorithm>(
input: (KeyPair<A>, Vec<u8>),
) -> bool
where
<A as AsymmetricKey>::PubAlg: VerificationAlgorithm,
{
let (sk, pk) = input.0.into_keys();
let data = input.1;

let signature = sk.sign(&data);
signature.verify(&pk, &data) == Verification::Success
}

pub(crate) fn keypair_signing_ko<A: AsymmetricKey + SigningAlgorithm>(
input: (KeyPair<A>, KeyPair<A>, Vec<u8>),
) -> bool
where
<A as AsymmetricKey>::PubAlg: VerificationAlgorithm,
{
let (sk, pk) = input.0.into_keys();
let pk_random = input.1.public_key();
let data = input.2;

if &pk == pk_random {
return true;
}

let signature = sk.sign(&data);
signature.verify(pk_random, &data) == Verification::Failed
}
}

impl<U, A: VerificationAlgorithm> cbor_event::se::Serialize for Signature<U, A> {
fn serialize<'se, W: std::io::Write>(
&self,
Expand Down Expand Up @@ -292,3 +255,40 @@ impl<'de, U, A: VerificationAlgorithm> serde::de::Deserialize<'de> for Signature
})
}
}

#[cfg(test)]
pub(crate) mod test {
use super::*;
use crate::chain_crypto::key::{AsymmetricKey, KeyPair};

pub(crate) fn keypair_signing_ok<A: AsymmetricKey + SigningAlgorithm>(
input: (KeyPair<A>, Vec<u8>),
) -> bool
where
<A as AsymmetricKey>::PubAlg: VerificationAlgorithm,
{
let (sk, pk) = input.0.into_keys();
let data = input.1;

let signature = sk.sign(&data);
signature.verify(&pk, &data) == Verification::Success
}

pub(crate) fn keypair_signing_ko<A: AsymmetricKey + SigningAlgorithm>(
input: (KeyPair<A>, KeyPair<A>, Vec<u8>),
) -> bool
where
<A as AsymmetricKey>::PubAlg: VerificationAlgorithm,
{
let (sk, pk) = input.0.into_keys();
let pk_random = input.1.public_key();
let data = input.2;

if &pk == pk_random {
return true;
}

let signature = sk.sign(&data);
signature.verify(pk_random, &data) == Verification::Failed
}
}
Loading