Migrate import statements and macros to Rust 2018.

This commit is contained in:
Guillaume Endignoux
2020-09-23 13:47:20 +02:00
parent 55c9053baf
commit 85a34ad085
35 changed files with 81 additions and 70 deletions

View File

@@ -1,10 +1,8 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate alloc;
extern crate cbor;
use alloc::vec::Vec;
use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
if let Ok(value) = cbor::read(data) {

View File

@@ -18,7 +18,6 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate core;
#[macro_use]
pub mod macros;
pub mod reader;
pub mod values;

View File

@@ -38,8 +38,7 @@ use core::iter::Peekable;
///
/// ```rust
/// # extern crate alloc;
/// # #[macro_use]
/// # extern crate cbor;
/// # use cbor::destructure_cbor_map;
/// #
/// # fn main() {
/// # let map = alloc::collections::BTreeMap::new();
@@ -54,8 +53,6 @@ use core::iter::Peekable;
///
/// ```rust
/// # extern crate alloc;
/// # #[macro_use]
/// # extern crate cbor;
/// #
/// # fn main() {
/// # let mut map = alloc::collections::BTreeMap::<cbor::KeyType, _>::new();
@@ -71,7 +68,7 @@ macro_rules! destructure_cbor_map {
// sorted - the behavior is unspecified if the keys are not sorted.
// Therefore, in test mode we add assertions that the keys are indeed sorted.
#[cfg(test)]
assert_sorted_keys!($( $key, )+);
$crate::assert_sorted_keys!($( $key, )+);
use $crate::values::{IntoCborKey, Value};
use $crate::macros::destructure_cbor_map_peek_value;
@@ -144,7 +141,7 @@ macro_rules! assert_sorted_keys {
k2,
);
}
assert_sorted_keys!($key2, $( $keys, )*);
$crate::assert_sorted_keys!($key2, $( $keys, )*);
};
}
@@ -227,7 +224,7 @@ macro_rules! cbor_array_vec {
}};
}
#[cfg(test)]
#[macro_export]
macro_rules! cbor_true {
( ) => {
$crate::values::Value::Simple($crate::values::SimpleValue::TrueValue)
@@ -248,7 +245,7 @@ macro_rules! cbor_null {
};
}
#[cfg(test)]
#[macro_export]
macro_rules! cbor_undefined {
( ) => {
$crate::values::Value::Simple($crate::values::SimpleValue::Undefined)
@@ -267,28 +264,28 @@ macro_rules! cbor_bool {
#[macro_export]
macro_rules! cbor_unsigned {
( $x:expr ) => {
cbor_key_unsigned!($x).into()
$crate::cbor_key_unsigned!($x).into()
};
}
#[macro_export]
macro_rules! cbor_int {
( $x:expr ) => {
cbor_key_int!($x).into()
$crate::cbor_key_int!($x).into()
};
}
#[macro_export]
macro_rules! cbor_text {
( $x:expr ) => {
cbor_key_text!($x).into()
$crate::cbor_key_text!($x).into()
};
}
#[macro_export]
macro_rules! cbor_bytes {
( $x:expr ) => {
cbor_key_bytes!($x).into()
$crate::cbor_key_bytes!($x).into()
};
}
@@ -296,7 +293,7 @@ macro_rules! cbor_bytes {
#[macro_export]
macro_rules! cbor_bytes_lit {
( $x:expr ) => {
cbor_bytes!(($x as &[u8]).to_vec())
$crate::cbor_bytes!(($x as &[u8]).to_vec())
};
}

View File

@@ -13,6 +13,7 @@
// limitations under the License.
use super::values::{Constants, KeyType, SimpleValue, Value};
use crate::{cbor_array_vec, cbor_bytes_lit, cbor_map_btree, cbor_text, cbor_unsigned};
use alloc::collections::BTreeMap;
use alloc::str;
use alloc::vec::Vec;
@@ -214,6 +215,10 @@ impl<'a> Reader<'a> {
#[cfg(test)]
mod test {
use super::*;
use crate::{
cbor_array, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_true,
cbor_undefined,
};
#[test]
fn test_read_unsigned() {

View File

@@ -239,6 +239,8 @@ where
#[cfg(test)]
mod test {
use crate::{cbor_key_bytes, cbor_key_int, cbor_key_text};
#[test]
fn test_key_type_ordering() {
assert!(cbor_key_int!(0) < cbor_key_int!(23));

View File

@@ -92,6 +92,10 @@ impl<'a> Writer<'a> {
#[cfg(test)]
mod test {
use super::*;
use crate::{
cbor_array, cbor_array_vec, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null,
cbor_text, cbor_true, cbor_undefined,
};
fn write_return(value: Value) -> Option<Vec<u8>> {
let mut encoded_cbor = Vec::new();

View File

@@ -14,6 +14,7 @@
use super::util::{xor_block_16, Block16};
use super::{Decrypt16BytesBlock, Encrypt16BytesBlock};
use arrayref::{array_mut_ref, array_ref};
/** A portable and naive textbook implementation of AES-256 **/
type Word = [u8; 4];

View File

@@ -13,7 +13,9 @@
// limitations under the License.
use super::super::rng256::Rng256;
use alloc::vec;
use alloc::vec::Vec;
use arrayref::{array_mut_ref, array_ref};
use byteorder::{BigEndian, ByteOrder};
use core::ops::{Add, AddAssign, Sub, SubAssign};
use subtle::{self, Choice, ConditionallySelectable, ConstantTimeEq};

View File

@@ -16,6 +16,10 @@ use super::exponent256::ExponentP256;
use super::gfp256::GFP256;
use super::int256::Int256;
use super::montgomery::Montgomery;
#[cfg(test)]
use arrayref::array_mut_ref;
#[cfg(feature = "std")]
use arrayref::array_ref;
use core::ops::Add;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

View File

@@ -19,7 +19,12 @@ use super::ec::point::PointP256;
use super::hmac::hmac_256;
use super::rng256::Rng256;
use super::{Hash256, HashBlockSize64Bytes};
use alloc::vec;
use alloc::vec::Vec;
#[cfg(feature = "std")]
use arrayref::array_ref;
use arrayref::{array_mut_ref, mut_array_refs};
use cbor::{cbor_bytes, cbor_map_options};
use core::marker::PhantomData;
#[derive(Clone, PartialEq)]
@@ -349,9 +354,6 @@ mod test {
use super::super::rng256::ThreadRng256;
use super::super::sha256::Sha256;
use super::*;
extern crate hex;
extern crate ring;
extern crate untrusted;
// Run more test iterations in release mode, as the code should be faster.
#[cfg(not(debug_assertions))]

View File

@@ -13,6 +13,7 @@
// limitations under the License.
use super::{Hash256, HashBlockSize64Bytes};
use arrayref::array_ref;
use subtle::ConstantTimeEq;
const BLOCK_SIZE: usize = 64;
@@ -71,7 +72,6 @@ fn xor_pads(ipad: &mut [u8; BLOCK_SIZE], opad: &mut [u8; BLOCK_SIZE], key: &[u8]
mod test {
use super::super::sha256::Sha256;
use super::*;
extern crate hex;
#[test]
fn test_verify_hmac_valid() {

View File

@@ -15,14 +15,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(wrapping_int_impl)]
#[macro_use]
extern crate alloc;
extern crate subtle;
#[macro_use]
extern crate arrayref;
extern crate byteorder;
#[macro_use]
extern crate cbor;
pub mod aes256;
pub mod cbc;

View File

@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use arrayref::array_ref;
use libtock_drivers::rng;
// Lightweight RNG trait to generate uniformly distributed 256 bits.

View File

@@ -13,6 +13,7 @@
// limitations under the License.
use super::{Hash256, HashBlockSize64Bytes};
use arrayref::{array_mut_ref, array_ref};
use byteorder::{BigEndian, ByteOrder};
use core::num::Wrapping;
@@ -210,7 +211,6 @@ impl Sha256 {
#[cfg(test)]
mod test {
use super::*;
extern crate hex;
#[test]
fn test_choice() {

View File

@@ -15,11 +15,7 @@
/// Test vectors for AES-ECB from NIST's validation suite.
///
/// See also https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/aes/AESAVS.pdf
#[macro_use]
extern crate arrayref;
extern crate hex;
extern crate regex;
use arrayref::array_ref;
use crypto::{aes256, Decrypt16BytesBlock, Encrypt16BytesBlock};
use regex::Regex;
use std::fs::File;