use super::*;
const VISIBILITY_CONSTANT: [bool; 2] = [false, false];
const VISIBILITY_PUBLIC: [bool; 2] = [false, true];
const VISIBILITY_PRIVATE: [bool; 2] = [true, false];
impl<A: Aleo> Entry<A, Plaintext<A>> {
pub(super) fn write_bits_le_with_visibility_as_mode(&self, vec: &mut Vec<Boolean<A>>, mode: Mode) {
let boolean_new = |mode: Mode, value: bool| match mode {
Mode::Constant => Boolean::constant(value),
Mode::Public => Boolean::new(Mode::Public, value),
Mode::Private => Boolean::new(Mode::Private, value),
};
let visibility_bits = match self {
Self::Constant(..) => VISIBILITY_CONSTANT,
Self::Public(..) => VISIBILITY_PUBLIC,
Self::Private(..) => VISIBILITY_PRIVATE,
};
vec.extend(visibility_bits.iter().map(|&bit| boolean_new(mode, bit)));
match self {
Self::Constant(plaintext) => plaintext.write_bits_le(vec),
Self::Public(plaintext) => plaintext.write_bits_le(vec),
Self::Private(plaintext) => plaintext.write_bits_le(vec),
};
}
}
impl<A: Aleo> ToBits for Entry<A, Plaintext<A>> {
type Boolean = Boolean<A>;
fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
self.write_bits_le_with_visibility_as_mode(vec, Mode::Constant);
}
fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
let visibility_bits = match self {
Self::Constant(..) => VISIBILITY_CONSTANT,
Self::Public(..) => VISIBILITY_PUBLIC,
Self::Private(..) => VISIBILITY_PRIVATE,
};
vec.extend(visibility_bits.iter().map(|&bit| Boolean::constant(bit)));
match self {
Self::Constant(plaintext) => plaintext.write_bits_be(vec),
Self::Public(plaintext) => plaintext.write_bits_be(vec),
Self::Private(plaintext) => plaintext.write_bits_be(vec),
};
}
}
impl<A: Aleo> ToBits for Entry<A, Ciphertext<A>> {
type Boolean = Boolean<A>;
fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
let visibility_bits = match self {
Self::Constant(..) => VISIBILITY_CONSTANT,
Self::Public(..) => VISIBILITY_PUBLIC,
Self::Private(..) => VISIBILITY_PRIVATE,
};
vec.extend(visibility_bits.iter().map(|&bit| Boolean::constant(bit)));
match self {
Self::Constant(plaintext) => plaintext.write_bits_le(vec),
Self::Public(plaintext) => plaintext.write_bits_le(vec),
Self::Private(plaintext) => plaintext.write_bits_le(vec),
};
}
fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
let visibility_bits = match self {
Self::Constant(..) => VISIBILITY_CONSTANT,
Self::Public(..) => VISIBILITY_PUBLIC,
Self::Private(..) => VISIBILITY_PRIVATE,
};
vec.extend(visibility_bits.iter().map(|&bit| Boolean::constant(bit)));
match self {
Self::Constant(plaintext) => plaintext.write_bits_be(vec),
Self::Public(plaintext) => plaintext.write_bits_be(vec),
Self::Private(plaintext) => plaintext.write_bits_be(vec),
};
}
}