Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
  • Loading branch information
dhuseby committed Aug 28, 2024
1 parent a324893 commit ea97df0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 52 deletions.
14 changes: 7 additions & 7 deletions src/attrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum AttrId {
impl AttrId {
/// Get the code for the attribute id
pub fn code(&self) -> u8 {
self.clone().into()
(*self).into()
}

/// Convert the attribute id to &str
Expand All @@ -45,9 +45,9 @@ impl AttrId {
}
}

impl Into<u8> for AttrId {
fn into(self) -> u8 {
self as u8
impl From<AttrId> for u8 {
fn from(val: AttrId) -> Self {
val as u8
}
}

Expand All @@ -68,9 +68,9 @@ impl TryFrom<u8> for AttrId {
}
}

impl Into<Vec<u8>> for AttrId {
fn into(self) -> Vec<u8> {
self.code().encode_into()
impl From<AttrId> for Vec<u8> {
fn from(val: AttrId) -> Self {
val.code().encode_into()
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/ms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ impl EncodingInfo for Multisig {
}
}

impl Into<Vec<u8>> for Multisig {
fn into(self) -> Vec<u8> {
impl From<Multisig> for Vec<u8> {
fn from(val: Multisig) -> Self {
let mut v = Vec::default();
// add in the sigil
v.append(&mut SIGIL.into());
// add in the signature codec
v.append(&mut self.codec.into());
v.append(&mut val.codec.into());
// add in the message
v.append(&mut Varbytes(self.message.clone()).into());
v.append(&mut Varbytes(val.message.clone()).into());
// add in the number of attributes
v.append(&mut Varuint(self.attributes.len()).into());
v.append(&mut Varuint(val.attributes.len()).into());
// add in the attributes
self.attributes.iter().for_each(|(id, attr)| {
val.attributes.iter().for_each(|(id, attr)| {
v.append(&mut (*id).into());
v.append(&mut Varbytes(attr.clone()).into());
});
Expand Down Expand Up @@ -167,7 +167,7 @@ impl fmt::Debug for Multisig {
"{:?} - {:?} - {}",
SIGIL,
self.codec(),
if self.message.len() > 0 {
if !self.message.is_empty() {
"Combined"
} else {
"Detached"
Expand Down Expand Up @@ -405,7 +405,7 @@ impl Builder {

fn with_attribute(mut self, attr: AttrId, data: &Vec<u8>) -> Self {
let mut attributes = self.attributes.unwrap_or_default();
attributes.insert(attr, data.clone());
attributes.insert(attr, data.to_owned());
self.attributes = Some(attributes);
self
}
Expand Down Expand Up @@ -457,7 +457,7 @@ impl Builder {
pub fn try_build_encoded(self) -> Result<EncodedMultisig, Error> {
Ok(BaseEncoded::new(
self.base_encoding
.unwrap_or_else(|| Multisig::preferred_encoding()),
.unwrap_or_else(Multisig::preferred_encoding),
self.try_build()?,
))
}
Expand Down
10 changes: 5 additions & 5 deletions src/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ impl<'de> Deserialize<'de> for AttrId {
where
E: Error,
{
Ok(AttrId::try_from(c).map_err(|e| Error::custom(e.to_string()))?)
AttrId::try_from(c).map_err(|e| Error::custom(e.to_string()))
}

fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
where
E: Error,
{
Ok(AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))?)
AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))
}

fn visit_borrowed_str<E>(self, s: &'de str) -> Result<Self::Value, E>
where
E: Error,
{
Ok(AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))?)
AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))
}

fn visit_string<E>(self, s: String) -> Result<Self::Value, E>
where
E: Error,
{
Ok(AttrId::try_from(s.as_str()).map_err(|e| Error::custom(e.to_string()))?)
AttrId::try_from(s.as_str()).map_err(|e| Error::custom(e.to_string()))
}
}

Expand All @@ -65,7 +65,7 @@ impl<'de> Deserialize<'de> for Multisig {
where
D: Deserializer<'de>,
{
const FIELDS: &'static [&'static str] = &["codec", "message", "attributes"];
const FIELDS: &[&str] = &["codec", "message", "attributes"];

#[derive(Deserialize)]
#[serde(field_identifier, rename_all = "lowercase")]
Expand Down
58 changes: 27 additions & 31 deletions src/views/bls12381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum SchemeTypeId {
impl SchemeTypeId {
/// Get the code for the attribute id
pub fn code(&self) -> u8 {
self.clone().into()
(*self).into()
}

/// Convert the attribute id to &str
Expand All @@ -50,9 +50,9 @@ impl SchemeTypeId {
}
}

impl Into<u8> for SchemeTypeId {
fn into(self) -> u8 {
self as u8
impl From<SchemeTypeId> for u8 {
fn from(val: SchemeTypeId) -> Self {
val as u8
}
}

Expand All @@ -69,9 +69,9 @@ impl TryFrom<u8> for SchemeTypeId {
}
}

impl Into<SignatureSchemes> for SchemeTypeId {
fn into(self) -> SignatureSchemes {
match self {
impl From<SchemeTypeId> for SignatureSchemes {
fn from(val: SchemeTypeId) -> Self {
match val {
SchemeTypeId::Basic => SignatureSchemes::Basic,
SchemeTypeId::MessageAugmentation => SignatureSchemes::MessageAugmentation,
SchemeTypeId::ProofOfPossession => SignatureSchemes::ProofOfPossession,
Expand Down Expand Up @@ -115,9 +115,9 @@ where
}
}

impl Into<Vec<u8>> for SchemeTypeId {
fn into(self) -> Vec<u8> {
self.code().encode_into()
impl From<SchemeTypeId> for Vec<u8> {
fn from(val: SchemeTypeId) -> Self {
val.code().encode_into()
}
}

Expand Down Expand Up @@ -167,13 +167,13 @@ pub struct SigCombined(
pub Vec<u8>,
);

impl Into<Vec<u8>> for SigCombined {
fn into(self) -> Vec<u8> {
impl From<SigCombined> for Vec<u8> {
fn from(val: SigCombined) -> Self {
let mut v = Vec::default();
// add in the signature type id
v.append(&mut self.0.into());
v.append(&mut val.0.into());
// add in the signature bytes
v.append(&mut Varbytes(self.1.clone()).into());
v.append(&mut Varbytes(val.1.clone()).into());
v
}
}
Expand Down Expand Up @@ -214,19 +214,19 @@ pub struct SigShare(
pub Vec<u8>,
);

impl Into<Vec<u8>> for SigShare {
fn into(self) -> Vec<u8> {
impl From<SigShare> for Vec<u8> {
fn from(val: SigShare) -> Self {
let mut v = Vec::default();
// add in the share identifier
v.append(&mut Varuint(self.0).into());
v.append(&mut Varuint(val.0).into());
// add in the share threshold
v.append(&mut Varuint(self.1).into());
v.append(&mut Varuint(val.1).into());
// add in the share limit
v.append(&mut Varuint(self.2).into());
v.append(&mut Varuint(val.2).into());
// add in the share type id
v.append(&mut self.3.into());
v.append(&mut val.3.into());
// add in the share data
v.append(&mut Varbytes(self.4.clone()).into());
v.append(&mut Varbytes(val.4.clone()).into());
v
}
}
Expand Down Expand Up @@ -270,13 +270,13 @@ impl<'a> TryDecodeFrom<'a> for SigShare {
#[derive(Clone, Default)]
pub(crate) struct ThresholdData(pub(crate) BTreeMap<u8, SigShare>);

impl Into<Vec<u8>> for ThresholdData {
fn into(self) -> Vec<u8> {
impl From<ThresholdData> for Vec<u8> {
fn from(val: ThresholdData) -> Self {
let mut v = Vec::default();
// add in the number of sig shares
v.append(&mut Varuint(self.0.len()).into());
v.append(&mut Varuint(val.0.len()).into());
// add in the sig shares
self.0.iter().for_each(|(_, share)| {
val.0.iter().for_each(|(_, share)| {
v.append(&mut share.clone().into());
});
v
Expand Down Expand Up @@ -607,11 +607,7 @@ impl<'a> ThresholdView for View<'a> {
match av.payload_encoding() {
Ok(encoding) => Some(encoding),
Err(_) => {
if let Some(encoding) = encoding {
Some(encoding)
} else {
None
}
encoding
}
}
};
Expand Down Expand Up @@ -737,7 +733,7 @@ impl<'a> ThresholdView for View<'a> {
builder.try_build()
}
}
_ => return Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())),
_ => Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())),
}
}
}

0 comments on commit ea97df0

Please sign in to comment.