mirror of
https://github.com/trussed-dev/flexiber.git
synced 2026-06-20 04:16:10 -07:00
Fix clippy warnings
This commit is contained in:
committed by
sosthene-nitrokey
parent
ad5667b32b
commit
5d84e47887
+1
-1
@@ -120,7 +120,7 @@ impl<'a> Decoder<'a> {
|
||||
pub(crate) fn peek(&self) -> Option<u8> {
|
||||
self.remaining()
|
||||
.ok()
|
||||
.and_then(|bytes| bytes.get(0).cloned())
|
||||
.and_then(|bytes| bytes.first().cloned())
|
||||
}
|
||||
|
||||
/// Obtain the remaining bytes in this decoder from the current cursor
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ impl<'a> TryFrom<&'a [&'a dyn Encodable]> for Length {
|
||||
fn try_from(encodables: &[&dyn Encodable]) -> Result<Length> {
|
||||
encodables
|
||||
.iter()
|
||||
.fold(Ok(Length::zero()), |sum, encodable| {
|
||||
.try_fold(Length::zero(), |sum, encodable| {
|
||||
sum + encodable.encoded_length()?
|
||||
})
|
||||
}
|
||||
|
||||
+1
-4
@@ -209,10 +209,7 @@ impl Encodable for Tag {
|
||||
encoder.byte(NOT_LAST_TAG_OCTET_FLAG | (self.number >> 7) as u8)?;
|
||||
encoder.byte((self.number & 0x7F) as u8)
|
||||
}
|
||||
0x4000..=0xFFFF => {
|
||||
// todo()
|
||||
return Err(Error::from(ErrorKind::UnsupportedTagSize));
|
||||
}
|
||||
0x4000..=0xFFFF => Err(Error::from(ErrorKind::UnsupportedTagSize)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E, T> TaggedValue<&'a E, T>
|
||||
impl<E, T> TaggedValue<&'_ E, T>
|
||||
where
|
||||
E: Encodable,
|
||||
T: Copy + Encodable,
|
||||
@@ -42,7 +42,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E, T> Encodable for TaggedValue<&'a E, T>
|
||||
impl<E, T> Encodable for TaggedValue<&E, T>
|
||||
where
|
||||
E: Encodable,
|
||||
T: Copy + Encodable,
|
||||
@@ -119,7 +119,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Encodable for TaggedSlice<'a, T>
|
||||
impl<T> Encodable for TaggedSlice<'_, T>
|
||||
where
|
||||
T: Copy + Encodable,
|
||||
{
|
||||
|
||||
+25
-27
@@ -1,9 +1,7 @@
|
||||
// pub use der::{Decodable, Encodable};
|
||||
//! Trait definitions
|
||||
|
||||
use crate::{
|
||||
header::Header, Decoder, Encoder, Error, Length, Result, Tag, TagLike, TaggedSlice, TaggedValue,
|
||||
};
|
||||
use crate::{header::Header, Decoder, Encoder, Error, Length, Result, Tag, TaggedSlice};
|
||||
use core::convert::{TryFrom, TryInto};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
@@ -164,20 +162,6 @@ pub trait EncodableHeapless: Encodable {
|
||||
#[cfg(feature = "heapless")]
|
||||
impl<X> EncodableHeapless for X where X: Encodable {}
|
||||
|
||||
/// Types that can be tagged.
|
||||
pub(crate) trait Taggable<T: TagLike>: Sized {
|
||||
fn tagged(&self, tag: T) -> TaggedValue<&Self, T> {
|
||||
TaggedValue::new(tag, self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, X> Taggable<T> for X
|
||||
where
|
||||
X: Sized,
|
||||
T: TagLike,
|
||||
{
|
||||
}
|
||||
|
||||
// /// Types with an associated BER-TLV [`Tag`].
|
||||
// pub trait Tagged {
|
||||
// /// BER-TLV tag
|
||||
@@ -354,10 +338,24 @@ impl_array!(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::{Container, Taggable, Tagged};
|
||||
use crate::{Decodable, Encodable, Error, Result, Tag, TagLike, TaggedSlice};
|
||||
use super::{Container, Tagged};
|
||||
use crate::{Decodable, Encodable, Error, Result, Tag, TagLike, TaggedSlice, TaggedValue};
|
||||
use core::convert::TryFrom;
|
||||
|
||||
/// Types that can be tagged.
|
||||
pub(crate) trait Taggable<T: TagLike>: Sized {
|
||||
fn tagged(&self, tag: T) -> TaggedValue<&Self, T> {
|
||||
TaggedValue::new(tag, self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, X> Taggable<T> for X
|
||||
where
|
||||
X: Sized,
|
||||
T: TagLike,
|
||||
{
|
||||
}
|
||||
|
||||
// The types [u8; 2], [u8; 3], [u8; 4] stand in here for any types for the fields
|
||||
// of a struct that are Decodable + Encodable. This means they can decode to/encode from
|
||||
// a byte slice, but also that thye can declare their encoded length.
|
||||
@@ -578,13 +576,13 @@ mod tests {
|
||||
}
|
||||
|
||||
// no tag
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
struct T3 {
|
||||
// no tag
|
||||
s: S,
|
||||
// tag 0x02
|
||||
t: [u8; 3],
|
||||
}
|
||||
// #[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
// struct T3 {
|
||||
// // no tag
|
||||
// s: S,
|
||||
// // tag 0x02
|
||||
// t: [u8; 3],
|
||||
// }
|
||||
|
||||
// impl<'a> TryFrom<TaggedSlice<'a>> for T2 {
|
||||
// type Error = Error;
|
||||
@@ -655,7 +653,7 @@ mod tests {
|
||||
};
|
||||
let encoded = s.encode_to_slice(&mut buf).unwrap();
|
||||
|
||||
let mut decoder = crate::Decoder::new(&encoded);
|
||||
let mut decoder = crate::Decoder::new(encoded);
|
||||
let s: Option<S> = decoder.decode().unwrap();
|
||||
assert!(s.is_some());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user