summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/from.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/crypto-bigint/src/uint/from.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/crypto-bigint/src/uint/from.rs')
-rw-r--r--vendor/crypto-bigint/src/uint/from.rs76
1 files changed, 37 insertions, 39 deletions
diff --git a/vendor/crypto-bigint/src/uint/from.rs b/vendor/crypto-bigint/src/uint/from.rs
index daa5b7092..ac02f2ef2 100644
--- a/vendor/crypto-bigint/src/uint/from.rs
+++ b/vendor/crypto-bigint/src/uint/from.rs
@@ -1,9 +1,9 @@
-//! `From`-like conversions for [`UInt`].
+//! `From`-like conversions for [`Uint`].
-use crate::{Limb, UInt, WideWord, Word, U128, U64};
+use crate::{Limb, Uint, WideWord, Word, U128, U64};
-impl<const LIMBS: usize> UInt<LIMBS> {
- /// Create a [`UInt`] from a `u8` (const-friendly)
+impl<const LIMBS: usize> Uint<LIMBS> {
+ /// Create a [`Uint`] from a `u8` (const-friendly)
// TODO(tarcieri): replace with `const impl From<u8>` when stable
pub const fn from_u8(n: u8) -> Self {
assert!(LIMBS >= 1, "number of limbs must be greater than zero");
@@ -12,7 +12,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `u16` (const-friendly)
+ /// Create a [`Uint`] from a `u16` (const-friendly)
// TODO(tarcieri): replace with `const impl From<u16>` when stable
pub const fn from_u16(n: u16) -> Self {
assert!(LIMBS >= 1, "number of limbs must be greater than zero");
@@ -21,7 +21,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `u32` (const-friendly)
+ /// Create a [`Uint`] from a `u32` (const-friendly)
// TODO(tarcieri): replace with `const impl From<u32>` when stable
#[allow(trivial_numeric_casts)]
pub const fn from_u32(n: u32) -> Self {
@@ -31,7 +31,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `u64` (const-friendly)
+ /// Create a [`Uint`] from a `u64` (const-friendly)
// TODO(tarcieri): replace with `const impl From<u64>` when stable
#[cfg(target_pointer_width = "32")]
pub const fn from_u64(n: u64) -> Self {
@@ -42,7 +42,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `u64` (const-friendly)
+ /// Create a [`Uint`] from a `u64` (const-friendly)
// TODO(tarcieri): replace with `const impl From<u64>` when stable
#[cfg(target_pointer_width = "64")]
pub const fn from_u64(n: u64) -> Self {
@@ -52,11 +52,11 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `u128` (const-friendly)
+ /// Create a [`Uint`] from a `u128` (const-friendly)
// TODO(tarcieri): replace with `const impl From<u128>` when stable
pub const fn from_u128(n: u128) -> Self {
assert!(
- LIMBS >= (128 / Limb::BIT_SIZE),
+ LIMBS >= (128 / Limb::BITS),
"number of limbs must be greater than zero"
);
@@ -80,7 +80,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `Word` (const-friendly)
+ /// Create a [`Uint`] from a `Word` (const-friendly)
// TODO(tarcieri): replace with `const impl From<Word>` when stable
pub const fn from_word(n: Word) -> Self {
assert!(LIMBS >= 1, "number of limbs must be greater than zero");
@@ -89,18 +89,18 @@ impl<const LIMBS: usize> UInt<LIMBS> {
Self { limbs }
}
- /// Create a [`UInt`] from a `WideWord` (const-friendly)
+ /// Create a [`Uint`] from a `WideWord` (const-friendly)
// TODO(tarcieri): replace with `const impl From<WideWord>` when stable
pub const fn from_wide_word(n: WideWord) -> Self {
assert!(LIMBS >= 2, "number of limbs must be two or greater");
let mut limbs = [Limb::ZERO; LIMBS];
limbs[0].0 = n as Word;
- limbs[1].0 = (n >> Limb::BIT_SIZE) as Word;
+ limbs[1].0 = (n >> Limb::BITS) as Word;
Self { limbs }
}
}
-impl<const LIMBS: usize> From<u8> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<u8> for Uint<LIMBS> {
fn from(n: u8) -> Self {
// TODO(tarcieri): const where clause when possible
debug_assert!(LIMBS > 0, "limbs must be non-zero");
@@ -108,7 +108,7 @@ impl<const LIMBS: usize> From<u8> for UInt<LIMBS> {
}
}
-impl<const LIMBS: usize> From<u16> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<u16> for Uint<LIMBS> {
fn from(n: u16) -> Self {
// TODO(tarcieri): const where clause when possible
debug_assert!(LIMBS > 0, "limbs must be non-zero");
@@ -116,7 +116,7 @@ impl<const LIMBS: usize> From<u16> for UInt<LIMBS> {
}
}
-impl<const LIMBS: usize> From<u32> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<u32> for Uint<LIMBS> {
fn from(n: u32) -> Self {
// TODO(tarcieri): const where clause when possible
debug_assert!(LIMBS > 0, "limbs must be non-zero");
@@ -124,24 +124,23 @@ impl<const LIMBS: usize> From<u32> for UInt<LIMBS> {
}
}
-impl<const LIMBS: usize> From<u64> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<u64> for Uint<LIMBS> {
fn from(n: u64) -> Self {
// TODO(tarcieri): const where clause when possible
- debug_assert!(LIMBS >= (64 / Limb::BIT_SIZE), "not enough limbs");
+ debug_assert!(LIMBS >= (64 / Limb::BITS), "not enough limbs");
Self::from_u64(n)
}
}
-impl<const LIMBS: usize> From<u128> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<u128> for Uint<LIMBS> {
fn from(n: u128) -> Self {
// TODO(tarcieri): const where clause when possible
- debug_assert!(LIMBS >= (128 / Limb::BIT_SIZE), "not enough limbs");
+ debug_assert!(LIMBS >= (128 / Limb::BITS), "not enough limbs");
Self::from_u128(n)
}
}
#[cfg(target_pointer_width = "32")]
-#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "32")))]
impl From<U64> for u64 {
fn from(n: U64) -> u64 {
(n.limbs[0].0 as u64) | ((n.limbs[1].0 as u64) << 32)
@@ -149,7 +148,6 @@ impl From<U64> for u64 {
}
#[cfg(target_pointer_width = "64")]
-#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<U64> for u64 {
fn from(n: U64) -> u64 {
n.limbs[0].into()
@@ -163,31 +161,31 @@ impl From<U128> for u128 {
}
}
-impl<const LIMBS: usize> From<[Word; LIMBS]> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<[Word; LIMBS]> for Uint<LIMBS> {
fn from(arr: [Word; LIMBS]) -> Self {
Self::from_words(arr)
}
}
-impl<const LIMBS: usize> From<UInt<LIMBS>> for [Word; LIMBS] {
- fn from(n: UInt<LIMBS>) -> [Word; LIMBS] {
+impl<const LIMBS: usize> From<Uint<LIMBS>> for [Word; LIMBS] {
+ fn from(n: Uint<LIMBS>) -> [Word; LIMBS] {
*n.as_ref()
}
}
-impl<const LIMBS: usize> From<[Limb; LIMBS]> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<[Limb; LIMBS]> for Uint<LIMBS> {
fn from(limbs: [Limb; LIMBS]) -> Self {
Self { limbs }
}
}
-impl<const LIMBS: usize> From<UInt<LIMBS>> for [Limb; LIMBS] {
- fn from(n: UInt<LIMBS>) -> [Limb; LIMBS] {
+impl<const LIMBS: usize> From<Uint<LIMBS>> for [Limb; LIMBS] {
+ fn from(n: Uint<LIMBS>) -> [Limb; LIMBS] {
n.limbs
}
}
-impl<const LIMBS: usize> From<Limb> for UInt<LIMBS> {
+impl<const LIMBS: usize> From<Limb> for Uint<LIMBS> {
fn from(limb: Limb) -> Self {
limb.0.into()
}
@@ -198,40 +196,40 @@ mod tests {
use crate::{Limb, Word, U128};
#[cfg(target_pointer_width = "32")]
- use crate::U64 as UIntEx;
+ use crate::U64 as UintEx;
#[cfg(target_pointer_width = "64")]
- use crate::U128 as UIntEx;
+ use crate::U128 as UintEx;
#[test]
fn from_u8() {
- let n = UIntEx::from(42u8);
- assert_eq!(n.limbs(), &[Limb(42), Limb(0)]);
+ let n = UintEx::from(42u8);
+ assert_eq!(n.as_limbs(), &[Limb(42), Limb(0)]);
}
#[test]
fn from_u16() {
- let n = UIntEx::from(42u16);
- assert_eq!(n.limbs(), &[Limb(42), Limb(0)]);
+ let n = UintEx::from(42u16);
+ assert_eq!(n.as_limbs(), &[Limb(42), Limb(0)]);
}
#[test]
fn from_u64() {
- let n = UIntEx::from(42u64);
- assert_eq!(n.limbs(), &[Limb(42), Limb(0)]);
+ let n = UintEx::from(42u64);
+ assert_eq!(n.as_limbs(), &[Limb(42), Limb(0)]);
}
#[test]
fn from_u128() {
let n = U128::from(42u128);
- assert_eq!(&n.limbs()[..2], &[Limb(42), Limb(0)]);
+ assert_eq!(&n.as_limbs()[..2], &[Limb(42), Limb(0)]);
assert_eq!(u128::from(n), 42u128);
}
#[test]
fn array_round_trip() {
let arr1 = [1, 2];
- let n = UIntEx::from(arr1);
+ let n = UintEx::from(arr1);
let arr2: [Word; 2] = n.into();
assert_eq!(arr1, arr2);
}