Skip to content

Commit b9d0904

Browse files
authored
k256: clippy fixes (#401)
Ensures `k256` passes clippy under Rust 1.54
1 parent b6c77bc commit b9d0904

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

.github/workflows/workspace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: actions/checkout@v2
2121
- uses: actions-rs/toolchain@v1
2222
with:
23-
toolchain: 1.51.0 # MSRV
23+
toolchain: 1.51.0
2424
components: clippy
2525
override: true
2626
profile: minimal

k256/src/arithmetic/field.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl FieldElement {
9191
}
9292

9393
/// Returns the SEC1 encoding of this field element.
94-
pub fn to_bytes(&self) -> FieldBytes {
94+
pub fn to_bytes(self) -> FieldBytes {
9595
self.0.normalize().to_bytes()
9696
}
9797

@@ -204,8 +204,8 @@ impl FieldElement {
204204
// { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block:
205205
// 1, [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223]
206206

207-
let x2 = self.pow2k(1).mul(&self);
208-
let x3 = x2.pow2k(1).mul(&self);
207+
let x2 = self.pow2k(1).mul(self);
208+
let x3 = x2.pow2k(1).mul(self);
209209
let x6 = x3.pow2k(3).mul(&x3);
210210
let x9 = x6.pow2k(3).mul(&x3);
211211
let x11 = x9.pow2k(2).mul(&x2);

k256/src/arithmetic/field/field_10x26.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl FieldElement10x26 {
8484
}
8585

8686
/// Returns the SEC1 encoding of this field element.
87-
pub fn to_bytes(&self) -> FieldBytes {
87+
pub fn to_bytes(self) -> FieldBytes {
8888
let mut r = FieldBytes::default();
8989
r[0] = (self.0[9] >> 14) as u8;
9090
r[1] = (self.0[9] >> 6) as u8;

k256/src/arithmetic/field/field_5x52.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl FieldElement5x52 {
8282
}
8383

8484
/// Returns the SEC1 encoding of this field element.
85-
pub fn to_bytes(&self) -> FieldBytes {
85+
pub fn to_bytes(self) -> FieldBytes {
8686
let mut ret = FieldBytes::default();
8787
ret[0] = (self.0[4] >> 40) as u8;
8888
ret[1] = (self.0[4] >> 32) as u8;

k256/src/arithmetic/field/field_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl FieldElementImpl {
6666
CtOption::map(value, |x| Self::new_normalized(&x))
6767
}
6868

69-
pub fn to_bytes(&self) -> FieldBytes {
69+
pub fn to_bytes(self) -> FieldBytes {
7070
debug_assert!(self.normalized);
7171
self.value.to_bytes()
7272
}

k256/src/arithmetic/mul.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn lincomb_generic<const N: usize>(xs: &[ProjectivePoint; N], ks: &[Scalar; N])
252252

253253
let tables1 = static_zip_map(
254254
|x, r_sign| LookupTable::from(&ProjectivePoint::conditional_select(&x, &-x, r_sign)),
255-
&xs,
255+
xs,
256256
&r1_signs,
257257
LookupTable::default(),
258258
);

k256/src/arithmetic/scalar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl Scalar {
252252

253253
/// Modulo squares the scalar.
254254
pub fn square(&self) -> Self {
255-
self.mul(&self)
255+
self.mul(self)
256256
}
257257

258258
/// Right shifts the scalar. Note: not constant-time in `shift`.
@@ -468,7 +468,7 @@ impl AddAssign<Scalar> for Scalar {
468468

469469
impl AddAssign<&Scalar> for Scalar {
470470
fn add_assign(&mut self, rhs: &Scalar) {
471-
*self = Scalar::add(self, &rhs);
471+
*self = Scalar::add(self, rhs);
472472
}
473473
}
474474

k256/src/arithmetic/scalar/scalar_4x64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Scalar4x64 {
219219
}
220220

221221
/// Returns the SEC1 encoding of this scalar.
222-
pub fn to_bytes(&self) -> FieldBytes {
222+
pub fn to_bytes(self) -> FieldBytes {
223223
let mut ret = FieldBytes::default();
224224
ret[0..8].copy_from_slice(&self.0[3].to_be_bytes());
225225
ret[8..16].copy_from_slice(&self.0[2].to_be_bytes());
@@ -312,8 +312,8 @@ impl Scalar4x64 {
312312
/// in constant time.
313313
/// In other words, calculates `(high_bit * 2^256 + limbs) % modulus`.
314314
fn from_overflow(w: &[u64; 4], high_bit: Choice) -> Self {
315-
let (r2, underflow) = sbb_array_with_underflow(&w, &MODULUS);
316-
Self(conditional_select(&w, &r2, !underflow | high_bit))
315+
let (r2, underflow) = sbb_array_with_underflow(w, &MODULUS);
316+
Self(conditional_select(w, &r2, !underflow | high_bit))
317317
}
318318

319319
/// Right shifts a scalar by given number of bits.

k256/src/arithmetic/scalar/scalar_8x32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl Scalar8x32 {
248248
}
249249

250250
/// Returns the SEC1 encoding of this scalar.
251-
pub fn to_bytes(&self) -> FieldBytes {
251+
pub fn to_bytes(self) -> FieldBytes {
252252
let mut ret = FieldBytes::default();
253253
ret[0..4].copy_from_slice(&self.0[7].to_be_bytes());
254254
ret[4..8].copy_from_slice(&self.0[6].to_be_bytes());
@@ -413,8 +413,8 @@ impl Scalar8x32 {
413413
/// in constant time.
414414
/// In other words, calculates `(high_bit * 2^256 + limbs) % modulus`.
415415
fn from_overflow(w: &[u32; 8], high_bit: Choice) -> Self {
416-
let (r2, underflow) = sbb_array_with_underflow(&w, &MODULUS);
417-
Self(conditional_select(&w, &r2, !underflow | high_bit))
416+
let (r2, underflow) = sbb_array_with_underflow(w, &MODULUS);
417+
Self(conditional_select(w, &r2, !underflow | high_bit))
418418
}
419419

420420
/// Right shifts a scalar by given number of bits.

k256/src/ecdsa/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl From<PublicKey> for VerifyingKey {
118118

119119
impl From<&PublicKey> for VerifyingKey {
120120
fn from(public_key: &PublicKey) -> VerifyingKey {
121-
public_key.clone().into()
121+
VerifyingKey::from(*public_key)
122122
}
123123
}
124124

@@ -130,7 +130,7 @@ impl From<VerifyingKey> for PublicKey {
130130

131131
impl From<&VerifyingKey> for PublicKey {
132132
fn from(verifying_key: &VerifyingKey) -> PublicKey {
133-
verifying_key.inner.clone().into()
133+
verifying_key.inner.into()
134134
}
135135
}
136136

0 commit comments

Comments
 (0)