ark_ec/models/short_weierstrass/
serialization_flags.rsuse ark_ff::Field;
use ark_serialize::Flags;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum SWFlags {
YIsPositive = 0,
PointAtInfinity = 1 << 6,
YIsNegative = 1 << 7,
}
impl SWFlags {
#[inline]
pub fn infinity() -> Self {
SWFlags::PointAtInfinity
}
#[inline]
pub fn from_y_coordinate(y: impl Field) -> Self {
if y <= -y {
Self::YIsPositive
} else {
Self::YIsNegative
}
}
#[inline]
pub fn is_infinity(&self) -> bool {
matches!(self, SWFlags::PointAtInfinity)
}
#[inline]
pub fn is_positive(&self) -> Option<bool> {
match self {
SWFlags::PointAtInfinity => None,
SWFlags::YIsPositive => Some(true),
SWFlags::YIsNegative => Some(false),
}
}
}
impl Default for SWFlags {
#[inline]
fn default() -> Self {
SWFlags::YIsNegative
}
}
impl Flags for SWFlags {
const BIT_SIZE: usize = 2;
#[inline]
fn u8_bitmask(&self) -> u8 {
let mut mask = 0;
match self {
SWFlags::PointAtInfinity => mask |= 1 << 6,
SWFlags::YIsNegative => mask |= 1 << 7,
_ => (),
}
mask
}
#[inline]
fn from_u8(value: u8) -> Option<Self> {
let is_negative = (value >> 7) & 1 == 1;
let is_infinity = (value >> 6) & 1 == 1;
match (is_negative, is_infinity) {
(true, true) => None,
(false, true) => Some(SWFlags::PointAtInfinity),
(true, false) => Some(SWFlags::YIsNegative),
(false, false) => Some(SWFlags::YIsPositive),
}
}
}