Skip to content

Commit

Permalink
fix: resolve clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
augustocdias committed Aug 14, 2024
1 parent eff38af commit b278a84
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 262 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ eyre = "0.6"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
criterion = "0.5"
criterion = { version = "0.5", default_features = false }
pretty_assertions = "1.3"
proteus-wasm = { path = ".", package = "proteus-wasm", features = ["hazmat", "cryptobox-identity", "public-key-batch-verification"] }
wasm-bindgen-test = "0.3"
Expand Down
4 changes: 1 addition & 3 deletions crates/cbor-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ edition = "2021"
[lib]
name = "cbor"

[features]
random = ["quickcheck"]

[dependencies]
byteorder = "1.4"
half = "2.1"
rand = "0.8"

[dependencies.quickcheck]
version = "1.0"
Expand Down
38 changes: 16 additions & 22 deletions crates/cbor-codec/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
//! The module is structured as follows:
//!
//! 1. `Kernel` contains the basic decoding functionality, capable of
//! decoding simple unstructured types.
//! decoding simple unstructured types.
//! 2. `Decoder` directly decodes into native Rust types.
//! 3. `GenericDecoder` handles arbitrary CBOR items and decodes them
//! into an `Value` AST.
//! into an `Value` AST.
//!
//! # Example 1: Direct decoding
//!
Expand All @@ -36,19 +36,17 @@
//! use cbor::{Config, Decoder};
//! use std::io::Cursor;
//!
//! fn main() {
//! let input = Cursor::new(hex::decode("828301020383010203").unwrap());
//! let mut dec = Decoder::new(Config::default(), input);
//! let mut res = Vec::new();
//! let input = Cursor::new(hex::decode("828301020383010203").unwrap());
//! let mut dec = Decoder::new(Config::default(), input);
//! let mut res = Vec::new();
//! for _ in 0 .. dec.array().unwrap() {
//! let mut vec = Vec::new();
//! for _ in 0 .. dec.array().unwrap() {
//! let mut vec = Vec::new();
//! for _ in 0 .. dec.array().unwrap() {
//! vec.push(dec.u8().unwrap())
//! }
//! res.push(vec)
//! vec.push(dec.u8().unwrap())
//! }
//! assert_eq!(vec![vec![1, 2, 3], vec![1, 2, 3]], res)
//! res.push(vec)
//! }
//! assert_eq!(vec![vec![1, 2, 3], vec![1, 2, 3]], res)
//! ```
//!
//! # Example 3: Generic decoding
Expand All @@ -58,14 +56,12 @@
//! use cbor::value::{self, Key};
//! use std::io::Cursor;
//!
//! fn main() {
//! let input = Cursor::new(hex::decode("a2616101028103").unwrap());
//! let mut d = GenericDecoder::new(Config::default(), input);
//! let value = d.value().unwrap();
//! let c = value::Cursor::new(&value);
//! assert_eq!(Some(1), c.field("a").u8());
//! assert_eq!(Some(3), c.get(Key::u64(2)).at(0).u8())
//! }
//! let input = Cursor::new(hex::decode("a2616101028103").unwrap());
//! let mut d = GenericDecoder::new(Config::default(), input);
//! let value = d.value().unwrap();
//! let c = value::Cursor::new(&value);
//! assert_eq!(Some(1), c.field("a").u8());
//! assert_eq!(Some(3), c.get(Key::u64(2)).at(0).u8())
//! ```
//!
//! # Example 4: Direct decoding (optional value)
Expand All @@ -90,7 +86,6 @@ use std::fmt;
use std::io;
use std::str::{from_utf8, Utf8Error};
use std::string;
use std::{i16, i32, i64, i8};

// Decoder Configuration ////////////////////////////////////////////////////

Expand Down Expand Up @@ -1349,7 +1344,6 @@ mod tests {
use crate::value::{self, Int, Key, Simple, Value};
use std::collections::BTreeMap;
use std::io::Cursor;
use std::{f32, f64, u64};

#[test]
fn unsigned() {
Expand Down
38 changes: 16 additions & 22 deletions crates/cbor-codec/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
//! use cbor::Encoder;
//! use std::io::Cursor;
//!
//! fn main() {
//! let mut e = Encoder::new(Cursor::new(Vec::new()));
//! e.u16(1000).unwrap();
//! assert_eq!(hex::decode("1903e8").unwrap(), e.into_writer().into_inner())
//! }
//! let mut e = Encoder::new(Cursor::new(Vec::new()));
//! e.u16(1000).unwrap();
//! assert_eq!(hex::decode("1903e8").unwrap(), e.into_writer().into_inner())
//! ```
//!
//! # Example 2: Direct encoding (indefinite string)
Expand All @@ -28,12 +26,10 @@
//! use cbor::Encoder;
//! use std::io::Cursor;
//!
//! fn main() {
//! let mut e = Encoder::new(Cursor::new(Vec::new()));
//! e.text_iter(vec!["strea", "ming"].into_iter()).unwrap();
//! let output = hex::decode("7f657374726561646d696e67ff").unwrap();
//! assert_eq!(output, e.into_writer().into_inner())
//! }
//! let mut e = Encoder::new(Cursor::new(Vec::new()));
//! e.text_iter(vec!["strea", "ming"].into_iter()).unwrap();
//! let output = hex::decode("7f657374726561646d696e67ff").unwrap();
//! assert_eq!(output, e.into_writer().into_inner())
//! ```
//!
//! # Example 3: Direct encoding (nested array)
Expand All @@ -43,16 +39,14 @@
//! use cbor::Encoder;
//! use std::io::Cursor;
//!
//! fn main() {
//! let mut e = Encoder::new(Cursor::new(Vec::new()));
//! e.array(3)
//! .and(e.u8(1))
//! .and(e.array(2)).and(e.u8(2)).and(e.u8(3))
//! .and(e.array(2)).and(e.u8(4)).and(e.u8(5))
//! .unwrap();
//! let output = hex::decode("8301820203820405").unwrap();
//! assert_eq!(output, e.into_writer().into_inner())
//! }
//! let mut e = Encoder::new(Cursor::new(Vec::new()));
//! e.array(3)
//! .and(e.u8(1))
//! .and(e.array(2)).and(e.u8(2)).and(e.u8(3))
//! .and(e.array(2)).and(e.u8(4)).and(e.u8(5))
//! .unwrap();
//! let output = hex::decode("8301820203820405").unwrap();
//! assert_eq!(output, e.into_writer().into_inner())
//! ```
use crate::types::{Tag, Type};
Expand Down Expand Up @@ -727,7 +721,7 @@ mod tests {
where
F: FnMut(Encoder<Cursor<&mut [u8]>>) -> EncodeResult,
{
let mut buffer = vec![0u8; 128];
let mut buffer = [0u8; 128];
assert!(f(Encoder::new(Cursor::new(&mut buffer[..]))).is_ok());
assert_eq!(
&hex::decode(expected).unwrap()[..],
Expand Down
3 changes: 0 additions & 3 deletions crates/cbor-codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ pub mod slice;
pub mod types;
pub mod value;

#[cfg(feature = "random")]
pub mod random;

pub use crate::decoder::{maybe, opt, or_break};
pub use crate::decoder::{Config, DecodeError, DecodeResult, Decoder, GenericDecoder};
pub use crate::encoder::{EncodeError, EncodeResult, Encoder, GenericEncoder};
172 changes: 0 additions & 172 deletions crates/cbor-codec/src/random.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/cbor-codec/src/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

//! `Skip` trait to allow efficient skipping of consecutive bytes.
use std::i64;
use std::io::{Result, Error, ErrorKind, Seek, SeekFrom};
use std::io::{Error, ErrorKind, Result, Seek, SeekFrom};

/// Type which supports skipping a number of bytes.
///
Expand All @@ -21,7 +20,7 @@ impl<A: Seek> Skip for A {
/// `n` must be in range `[0, i64::MAX]`.
fn skip(&mut self, n: u64) -> Result<()> {
if n > i64::MAX as u64 {
return Err(Error::new(ErrorKind::Other, "n too large"))
return Err(Error::new(ErrorKind::Other, "n too large"));
}
self.seek(SeekFrom::Current(n as i64)).and(Ok(()))
}
Expand Down
1 change: 0 additions & 1 deletion crates/cbor-codec/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use crate::types::Tag;
use std::collections::{BTreeMap, LinkedList};
use std::i64;

/// The generic CBOR representation.
#[derive(Clone, Debug, PartialEq, PartialOrd)]
Expand Down
Loading

0 comments on commit b278a84

Please sign in to comment.