Use alloc
instead of std
when possible.
This commit is contained in:
parent
0c962674a1
commit
7d36600ec8
2
STYLE.md
2
STYLE.md
@ -88,7 +88,7 @@ The C code generally uses the C `int` type as a return value, where 1 indicates
|
|||||||
success and 0 indicates failure. The module [ring::bssl](src/bssl.rs) contains
|
success and 0 indicates failure. The module [ring::bssl](src/bssl.rs) contains
|
||||||
a [transparent] `Result` type which should be used as the return type when
|
a [transparent] `Result` type which should be used as the return type when
|
||||||
declaring foreign functions which follow this convention. A
|
declaring foreign functions which follow this convention. A
|
||||||
`ring::bssl::Result` should be converted to a `std::result::Result` using the
|
`ring::bssl::Result` should be converted to a `core::result::Result` using the
|
||||||
pattern in the following example (note the placement of `unsafe`):
|
pattern in the following example (note the placement of `unsafe`):
|
||||||
|
|
||||||
[transparent]: https://doc.rust-lang.org/nightly/reference/type-layout.html#the-transparent-representation
|
[transparent]: https://doc.rust-lang.org/nightly/reference/type-layout.html#the-transparent-representation
|
||||||
|
@ -142,8 +142,8 @@ pub const KEY_LEN: usize = KEY_BLOCKS * BLOCK_LEN;
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test;
|
use crate::test;
|
||||||
|
use alloc::vec;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use std::vec;
|
|
||||||
|
|
||||||
// This verifies the encryption functionality provided by ChaCha20_ctr32
|
// This verifies the encryption functionality provided by ChaCha20_ctr32
|
||||||
// is successful when either computed on disjoint input/output buffers,
|
// is successful when either computed on disjoint input/output buffers,
|
||||||
|
@ -14,5 +14,8 @@
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod constant;
|
pub mod constant;
|
||||||
|
|
||||||
|
#[cfg(feature = "use_heap")]
|
||||||
pub mod bigint;
|
pub mod bigint;
|
||||||
|
|
||||||
pub mod montgomery;
|
pub mod montgomery;
|
||||||
|
@ -43,11 +43,11 @@ use crate::{
|
|||||||
bits, bssl, c, error,
|
bits, bssl, c, error,
|
||||||
limb::{self, Limb, LimbMask, LIMB_BITS, LIMB_BYTES},
|
limb::{self, Limb, LimbMask, LIMB_BITS, LIMB_BYTES},
|
||||||
};
|
};
|
||||||
|
use alloc::{borrow::ToOwned as _, boxed::Box, vec, vec::Vec};
|
||||||
use core::{
|
use core::{
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
use std::{borrow::ToOwned as _, boxed::Box, vec, vec::Vec};
|
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
pub unsafe trait Prime {}
|
pub unsafe trait Prime {}
|
||||||
@ -1292,7 +1292,7 @@ extern "C" {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test;
|
use crate::test;
|
||||||
use std::format;
|
use alloc::format;
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
// Type-level representation of an arbitrary modulus.
|
// Type-level representation of an arbitrary modulus.
|
||||||
|
@ -489,7 +489,7 @@ mod tests {
|
|||||||
mod max_input {
|
mod max_input {
|
||||||
use super::super::super::digest;
|
use super::super::super::digest;
|
||||||
use crate::polyfill;
|
use crate::polyfill;
|
||||||
use std::vec;
|
use alloc::vec;
|
||||||
|
|
||||||
macro_rules! max_input_tests {
|
macro_rules! max_input_tests {
|
||||||
( $algorithm_name:ident ) => {
|
( $algorithm_name:ident ) => {
|
||||||
|
@ -440,7 +440,8 @@ extern "C" {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test;
|
use crate::test;
|
||||||
use std::{format, print, vec, vec::Vec};
|
use alloc::{format, vec, vec::Vec};
|
||||||
|
use std::print;
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
const ZERO_SCALAR: Scalar = Scalar {
|
const ZERO_SCALAR: Scalar = Scalar {
|
||||||
|
@ -196,7 +196,7 @@ impl KeyRejected {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "use_heap")]
|
#[cfg(feature = "use_std")]
|
||||||
impl std::error::Error for KeyRejected {
|
impl std::error::Error for KeyRejected {
|
||||||
fn cause(&self) -> Option<&dyn std::error::Error> {
|
fn cause(&self) -> Option<&dyn std::error::Error> {
|
||||||
None
|
None
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
use super::{der::*, writer::*, *};
|
use super::{der::*, writer::*, *};
|
||||||
use std::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
pub(crate) fn write_positive_integer(output: &mut dyn Accumulator, value: &Positive) {
|
pub(crate) fn write_positive_integer(output: &mut dyn Accumulator, value: &Positive) {
|
||||||
let first_byte = value.first_byte();
|
let first_byte = value.first_byte();
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
use std::{boxed::Box, vec::Vec};
|
use alloc::{boxed::Box, vec::Vec};
|
||||||
|
|
||||||
pub trait Accumulator {
|
pub trait Accumulator {
|
||||||
fn write_byte(&mut self, value: u8);
|
fn write_byte(&mut self, value: u8);
|
||||||
|
@ -62,6 +62,9 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(feature = "internal_benches", allow(unstable_features), feature(test))]
|
#![cfg_attr(feature = "internal_benches", allow(unstable_features), feature(test))]
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "use_heap"))]
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "use_heap"))]
|
#[cfg(any(test, feature = "use_heap"))]
|
||||||
extern crate std;
|
extern crate std;
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ rsa_pss_padding!(
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{digest, error, test};
|
use crate::{digest, error, test};
|
||||||
use std::vec;
|
use alloc::vec;
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -24,7 +24,7 @@ use crate::{
|
|||||||
io::{self, der, der_writer},
|
io::{self, der, der_writer},
|
||||||
pkcs8, rand, signature,
|
pkcs8, rand, signature,
|
||||||
};
|
};
|
||||||
use std::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
/// An RSA key pair, used for signing.
|
/// An RSA key pair, used for signing.
|
||||||
|
@ -122,8 +122,8 @@ use crate::bits;
|
|||||||
|
|
||||||
use crate::{digest, error};
|
use crate::{digest, error};
|
||||||
|
|
||||||
use std::{format, string::String, vec::Vec};
|
use alloc::{format, string::String, vec::Vec};
|
||||||
use std::{panic, println};
|
use std::println;
|
||||||
|
|
||||||
/// `compile_time_assert_clone::<T>();` fails to compile if `T` doesn't
|
/// `compile_time_assert_clone::<T>();` fails to compile if `T` doesn't
|
||||||
/// implement `Clone`.
|
/// implement `Clone`.
|
||||||
@ -311,7 +311,7 @@ where
|
|||||||
|
|
||||||
#[allow(box_pointers)]
|
#[allow(box_pointers)]
|
||||||
while let Some(mut test_case) = parse_test_case(&mut current_section, lines) {
|
while let Some(mut test_case) = parse_test_case(&mut current_section, lines) {
|
||||||
let result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||||
f(¤t_section, &mut test_case)
|
f(¤t_section, &mut test_case)
|
||||||
}));
|
}));
|
||||||
let result = match result {
|
let result = match result {
|
||||||
|
@ -45,8 +45,6 @@ fn ecdsa_from_pkcs8_test() {
|
|||||||
test::run(
|
test::run(
|
||||||
test_file!("ecdsa_from_pkcs8_tests.txt"),
|
test_file!("ecdsa_from_pkcs8_tests.txt"),
|
||||||
|section, test_case| {
|
|section, test_case| {
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
assert_eq!(section, "");
|
assert_eq!(section, "");
|
||||||
|
|
||||||
let curve_name = test_case.consume_string("Curve");
|
let curve_name = test_case.consume_string("Curve");
|
||||||
@ -85,7 +83,7 @@ fn ecdsa_from_pkcs8_test() {
|
|||||||
(Ok(_), None) => (),
|
(Ok(_), None) => (),
|
||||||
(Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e),
|
(Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e),
|
||||||
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e),
|
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e),
|
||||||
(Err(actual), Some(expected)) => assert_eq!(actual.description(), expected),
|
(Err(actual), Some(expected)) => assert_eq!(format!("{}", actual), expected),
|
||||||
};
|
};
|
||||||
|
|
||||||
match (
|
match (
|
||||||
@ -95,7 +93,7 @@ fn ecdsa_from_pkcs8_test() {
|
|||||||
(Ok(_), None) => (),
|
(Ok(_), None) => (),
|
||||||
(Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e),
|
(Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e),
|
||||||
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e),
|
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e),
|
||||||
(Err(actual), Some(expected)) => assert_eq!(actual.description(), expected),
|
(Err(actual), Some(expected)) => assert_eq!(format!("{}", actual), expected),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(signature::EcdsaKeyPair::from_pkcs8(other_fixed, &input).is_err());
|
assert!(signature::EcdsaKeyPair::from_pkcs8(other_fixed, &input).is_err());
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
use ring::{digest, error, pbkdf2, test, test_file};
|
use ring::{digest, error, pbkdf2, test, test_file};
|
||||||
use std::num::NonZeroU32;
|
use core::num::NonZeroU32;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn pbkdf2_tests() {
|
pub fn pbkdf2_tests() {
|
||||||
|
@ -46,8 +46,6 @@ fn rsa_from_pkcs8_test() {
|
|||||||
test::run(
|
test::run(
|
||||||
test_file!("rsa_from_pkcs8_tests.txt"),
|
test_file!("rsa_from_pkcs8_tests.txt"),
|
||||||
|section, test_case| {
|
|section, test_case| {
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
assert_eq!(section, "");
|
assert_eq!(section, "");
|
||||||
|
|
||||||
let input = test_case.consume_bytes("Input");
|
let input = test_case.consume_bytes("Input");
|
||||||
@ -57,7 +55,7 @@ fn rsa_from_pkcs8_test() {
|
|||||||
(Ok(_), None) => (),
|
(Ok(_), None) => (),
|
||||||
(Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e),
|
(Err(e), None) => panic!("Failed with error \"{}\", but expected to succeed", e),
|
||||||
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e),
|
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{}\"", e),
|
||||||
(Err(actual), Some(expected)) => assert_eq!(actual.description(), expected),
|
(Err(actual), Some(expected)) => assert_eq!(format!("{}", actual), expected),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -93,7 +91,6 @@ fn test_signature_rsa_pkcs1_sign() {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let key_pair = key_pair.unwrap();
|
let key_pair = key_pair.unwrap();
|
||||||
let key_pair = std::sync::Arc::new(key_pair);
|
|
||||||
|
|
||||||
// XXX: This test is too slow on Android ARM Travis CI builds.
|
// XXX: This test is too slow on Android ARM Travis CI builds.
|
||||||
// TODO: re-enable these tests on Android ARM.
|
// TODO: re-enable these tests on Android ARM.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user