cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Conversion from `[u64; 8]` into [`U512`] via the [`From`] trait.
use super::U512;

/// Creates a [`U512`] from an eight-element `u64` array in big-endian
/// order.
///
/// This is equivalent to [`U512::from_be_limbs`] but available through
/// the standard [`From`] trait for ergonomic conversions.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u512::U512;
///
/// let v: U512 = [0, 0, 0, 0, 0, 0, 0, 42u64].into();
/// assert_eq!(v, U512::from_be_limbs([0, 0, 0, 0, 0, 0, 0, 42]));
/// ```
impl From<[u64; 8]> for U512 {
    #[inline]
    fn from(value: [u64; 8]) -> Self {
        Self::from_be_limbs(value)
    }
}

#[cfg(test)]
mod ai_tests {
    use super::*;

    /// Round-trip from array through U512 back to limbs.
    #[test]
    fn round_trip() {
        let arr = [1u64, 2, 3, 4, 5, 6, 7, 8];
        let v = U512::from(arr);
        assert_eq!(v.to_be_limbs(), arr);
    }

    /// Zero array produces zero value.
    #[test]
    fn zero() {
        assert_eq!(U512::from([0u64; 8]), U512::from_be_limbs([0; 8]));
    }

    /// Matches from_be_limbs behavior.
    #[test]
    fn matches_from_be_limbs() {
        let arr = [0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11];
        assert_eq!(U512::from(arr), U512::from_be_limbs(arr));
    }
}