arcis 0.12.0

A standard library of types and functions for writing MPC circuits with the Arcis framework.
Documentation
//! Methods and associated constants on primitive integer types accepted by
//! the arcis interpreter.
//!
//! Each integer type listed here (`u8`, `u16`, …, `i128`, `usize`, `isize`)
//! is a documentation-only unit struct shadowing the primitive of the same
//! name within this module. The associated items mirror what the arcis
//! interpreter accepts inside `#[encrypted]` code; the values shown for
//! `BITS`/`MIN`/`MAX` are the primitive's own (clicking the type takes you to
//! the primitive's std page).

const STUB_MSG: &str = "arcis::std::integer is documentation-only; \
    inside `#[encrypted]` code the interpreter intercepts the real method before this stub runs.";

macro_rules! supported_int_common {
    ($t:ident, $primitive:ty, $bytes:literal) => {
        impl $t {
            /// Mirrors the primitive's `BITS` associated constant.
            pub const BITS: ::core::primitive::u32 = <$primitive>::BITS;
            /// Mirrors the primitive's `MIN` associated constant.
            pub const MIN: $primitive = <$primitive>::MIN;
            /// Mirrors the primitive's `MAX` associated constant.
            pub const MAX: $primitive = <$primitive>::MAX;

            /// Returns the smaller of `self` and `other`. Mirrors [`Ord::min`].
            pub fn min(self, other: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Returns the larger of `self` and `other`. Mirrors [`Ord::max`].
            pub fn max(self, other: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Computes the absolute difference between `self` and `other`.
            pub fn abs_diff(self, other: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Computes `self.div_ceil(other)` (ceiling division).
            pub fn div_ceil(self, other: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Wrapping (modular) addition.
            ///
            /// **Only works on integers whose type is statically known to the interpreter.**
            pub fn wrapping_add(self, rhs: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Wrapping (modular) subtraction.
            ///
            /// **Only works on integers whose type is statically known to the interpreter.**
            pub fn wrapping_sub(self, rhs: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Wrapping (modular) multiplication.
            ///
            /// **Only works on integers whose type is statically known to the interpreter.**
            pub fn wrapping_mul(self, rhs: Self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Returns the bytes of `self` in little-endian order.
            ///
            /// **Only works on integers whose type is statically known to the interpreter.**
            pub fn to_le_bytes(self) -> [::core::primitive::u8; $bytes] {
                unimplemented!("{STUB_MSG}")
            }

            /// Returns the bytes of `self` in big-endian order.
            ///
            /// **Only works on integers whose type is statically known to the interpreter.**
            pub fn to_be_bytes(self) -> [::core::primitive::u8; $bytes] {
                unimplemented!("{STUB_MSG}")
            }
        }
    };
}

macro_rules! supported_int_signed_only {
    ($t:ident) => {
        impl $t {
            /// Returns the absolute value of `self`.
            pub fn abs(self) -> Self {
                unimplemented!("{STUB_MSG}")
            }

            /// Returns `true` if `self` is strictly greater than zero.
            pub fn is_positive(self) -> ::core::primitive::bool {
                unimplemented!("{STUB_MSG}")
            }

            /// Returns `true` if `self` is strictly less than zero.
            pub fn is_negative(self) -> ::core::primitive::bool {
                unimplemented!("{STUB_MSG}")
            }
        }
    };
}

macro_rules! supported_unsigned {
    ($t:ident, $primitive:ty, $bytes:literal) => {
        /// Supported items on this integer type inside `#[encrypted]` code.
        #[allow(non_camel_case_types)]
        pub struct $t;
        supported_int_common!($t, $primitive, $bytes);
    };
}

macro_rules! supported_signed {
    ($t:ident, $primitive:ty, $bytes:literal) => {
        /// Supported items on this integer type inside `#[encrypted]` code.
        #[allow(non_camel_case_types)]
        pub struct $t;
        supported_int_common!($t, $primitive, $bytes);
        supported_int_signed_only!($t);
    };
}

supported_unsigned!(u8, ::core::primitive::u8, 1);
supported_unsigned!(u16, ::core::primitive::u16, 2);
supported_unsigned!(u32, ::core::primitive::u32, 4);
supported_unsigned!(u64, ::core::primitive::u64, 8);
supported_unsigned!(u128, ::core::primitive::u128, 16);
supported_unsigned!(usize, ::core::primitive::usize, 8);

supported_signed!(i8, ::core::primitive::i8, 1);
supported_signed!(i16, ::core::primitive::i16, 2);
supported_signed!(i32, ::core::primitive::i32, 4);
supported_signed!(i64, ::core::primitive::i64, 8);
supported_signed!(i128, ::core::primitive::i128, 16);
supported_signed!(isize, ::core::primitive::isize, 8);