diff --git a/src/limb.rs b/src/limb.rs index 56de64689..962608d29 100644 --- a/src/limb.rs +++ b/src/limb.rs @@ -18,7 +18,10 @@ //! Limbs ordered least-significant-limb to most-significant-limb. The bits //! limbs use the native endianness. -use crate::{c, error, polyfill::ArrayFlatMap}; +use crate::{ + c, error, + polyfill::{self, ArrayFlatMap}, +}; #[cfg(any(test, feature = "alloc"))] use crate::bits; @@ -251,7 +254,7 @@ pub fn big_endian_from_limbs(limbs: &[Limb], out: &mut [u8]) { pub fn unstripped_be_bytes(limbs: &[Limb]) -> impl ExactSizeIterator + Clone + '_ { // The unwrap is safe because a slice can never be larger than `usize` bytes. ArrayFlatMap::new(limbs.iter().rev().copied(), |limb| { - core::array::IntoIter::new(Limb::to_be_bytes(limb)) + polyfill::array::into_iter(Limb::to_be_bytes(limb)) }) .unwrap() } diff --git a/src/polyfill.rs b/src/polyfill.rs index a7f0f483f..0dbbbb025 100644 --- a/src/polyfill.rs +++ b/src/polyfill.rs @@ -27,6 +27,8 @@ pub fn usize_from_u32(x: u32) -> usize { #[macro_use] mod chunks_fixed; +pub(crate) mod array; + mod array_flat_map; pub(crate) mod array_map; diff --git a/src/polyfill/array.rs b/src/polyfill/array.rs new file mode 100644 index 000000000..1182f13ce --- /dev/null +++ b/src/polyfill/array.rs @@ -0,0 +1,20 @@ +// Copyright 2022 Brian Smith. +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION +// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// TODO: Remove this and use `IntoIterator::into_ter` once MSRV is 1.59.0 or later. +#[inline(always)] +pub(crate) fn into_iter(array: [T; N]) -> core::array::IntoIter { + #[allow(deprecated)] + core::array::IntoIter::new(array) +} diff --git a/src/polyfill/array_flat_map.rs b/src/polyfill/array_flat_map.rs index 572a5fa9f..b4db631b4 100644 --- a/src/polyfill/array_flat_map.rs +++ b/src/polyfill/array_flat_map.rs @@ -60,6 +60,7 @@ where #[cfg(test)] mod tests { use super::*; + use crate::polyfill; #[test] fn test_array_flat_map() { @@ -81,7 +82,7 @@ mod tests { ]; TEST_CASES.iter().copied().for_each(|(input, f, expected)| { let mapped = ArrayFlatMap::new(input.iter().copied(), |input| { - core::array::IntoIter::new(f(input)) + polyfill::array::into_iter(f(input)) }) .unwrap(); super::super::test::assert_iterator(mapped, expected); @@ -121,7 +122,7 @@ mod tests { remaining: input_len, }; let mapped = ArrayFlatMap::new(inner, |input| { - core::array::IntoIter::new(usize::to_be_bytes(input)) + polyfill::array::into_iter(usize::to_be_bytes(input)) }); assert_eq!(mapped.is_some(), is_some); if let Some(mapped) = mapped { diff --git a/src/rsa/public_exponent.rs b/src/rsa/public_exponent.rs index 083179292..6e2699e29 100644 --- a/src/rsa/public_exponent.rs +++ b/src/rsa/public_exponent.rs @@ -1,5 +1,5 @@ use crate::error; -use crate::polyfill::{ArrayFlatMap, LeadingZerosStripped}; +use crate::polyfill::{self, ArrayFlatMap, LeadingZerosStripped}; use core::num::NonZeroU64; /// The exponent `e` of an RSA public key. @@ -85,7 +85,7 @@ impl PublicExponent { pub fn be_bytes(&self) -> impl ExactSizeIterator + Clone + '_ { // The `unwrap()` won't fail as `self.0` is only a few bytes long. let bytes = ArrayFlatMap::new(core::iter::once(self.0.get()), |value| { - core::array::IntoIter::new(u64::to_be_bytes(value)) + polyfill::array::into_iter(u64::to_be_bytes(value)) }) .unwrap(); LeadingZerosStripped::new(bytes)