cnfy-uint 0.2.3

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

/// Converts a [`U384`] into its six `u64` limbs in big-endian order:
/// `[w0, w1, w2, w3, w4, w5]` where `w0` is the most significant.
///
/// This is the inverse of `From<[u64; 6]> for U384` and equivalent to
/// calling [`U384::to_be_limbs`].
///
/// # Examples
///
/// ```
/// use cnfy_uint::u384::U384;
///
/// let v = U384::from_be_limbs([1, 2, 3, 4, 5, 6]);
/// let arr: [u64; 6] = v.into();
/// assert_eq!(arr, [1, 2, 3, 4, 5, 6]);
/// ```
impl From<U384> for [u64; 6] {
    #[inline]
    fn from(value: U384) -> Self {
        [
            value.0[5], 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 U384 back to limbs.
    #[test]
    fn round_trip() {
        let arr = [0xA, 0xB, 0xC, 0xD, 0xE, 0xF];
        let v = U384::from_be_limbs(arr);
        let back: [u64; 6] = v.into();
        assert_eq!(back, arr);
    }

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

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