cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Conversion from [`U320`] into a `[u64; 5]` big-endian limb array.
use super::U320;

/// Converts a [`U320`] into its five `u64` limbs in big-endian order:
/// `[w0, w1, w2, w3, w4]` where `w0` is the most significant.
///
/// This is the inverse of `From<[u64; 5]> for U320` and equivalent to
/// calling [`U320::to_be_limbs`].
///
/// # Examples
///
/// ```
/// use cnfy_uint::u320::U320;
///
/// let v = U320::from_be_limbs([1, 2, 3, 4, 5]);
/// let arr: [u64; 5] = v.into();
/// assert_eq!(arr, [1, 2, 3, 4, 5]);
/// ```
impl From<U320> for [u64; 5] {
    #[inline]
    fn from(value: U320) -> Self {
        [value.0[4], value.0[3], value.0[2], value.0[1], value.0[0]]
    }
}

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

    /// Round-trip from limbs through U320 back to limbs.
    #[test]
    fn round_trip() {
        let arr = [0xA, 0xB, 0xC, 0xD, 0xE];
        let v = U320::from_be_limbs(arr);
        let back: [u64; 5] = v.into();
        assert_eq!(back, arr);
    }

    /// Zero converts to all-zero limbs.
    #[test]
    fn zero() {
        let arr: [u64; 5] = U320::from_be_limbs([0; 5]).into();
        assert_eq!(arr, [0; 5]);
    }

    /// All-max converts to all-max limbs.
    #[test]
    fn max() {
        let arr: [u64; 5] = U320::from_be_limbs([u64::MAX; 5]).into();
        assert_eq!(arr, [u64::MAX; 5]);
    }
}