snarkvm_circuit_program/data/record/entry/
to_bits.rs1use super::*;
17
18const VISIBILITY_CONSTANT: [bool; 2] = [false, false];
20const VISIBILITY_PUBLIC: [bool; 2] = [false, true];
22const VISIBILITY_PRIVATE: [bool; 2] = [true, false];
24
25impl<A: Aleo> Entry<A, Plaintext<A>> {
26 pub(super) fn write_bits_le_with_visibility_as_mode(&self, vec: &mut Vec<Boolean<A>>, mode: Mode) {
28 let boolean_new = |mode: Mode, value: bool| match mode {
31 Mode::Constant => Boolean::constant(value),
32 Mode::Public => Boolean::new(Mode::Public, value),
33 Mode::Private => Boolean::new(Mode::Private, value),
34 };
35 let visibility_bits = match self {
37 Self::Constant(..) => VISIBILITY_CONSTANT,
38 Self::Public(..) => VISIBILITY_PUBLIC,
39 Self::Private(..) => VISIBILITY_PRIVATE,
40 };
41 vec.extend(visibility_bits.iter().map(|&bit| boolean_new(mode, bit)));
42 match self {
44 Self::Constant(plaintext) => plaintext.write_bits_le(vec),
45 Self::Public(plaintext) => plaintext.write_bits_le(vec),
46 Self::Private(plaintext) => plaintext.write_bits_le(vec),
47 };
48 }
49}
50
51impl<A: Aleo> ToBits for Entry<A, Plaintext<A>> {
52 type Boolean = Boolean<A>;
53
54 fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
56 self.write_bits_le_with_visibility_as_mode(vec, Mode::Constant);
57 }
58
59 fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
61 let visibility_bits = match self {
62 Self::Constant(..) => VISIBILITY_CONSTANT,
63 Self::Public(..) => VISIBILITY_PUBLIC,
64 Self::Private(..) => VISIBILITY_PRIVATE,
65 };
66 vec.extend(visibility_bits.iter().map(|&bit| Boolean::constant(bit)));
67 match self {
68 Self::Constant(plaintext) => plaintext.write_bits_be(vec),
69 Self::Public(plaintext) => plaintext.write_bits_be(vec),
70 Self::Private(plaintext) => plaintext.write_bits_be(vec),
71 };
72 }
73}
74
75impl<A: Aleo> ToBits for Entry<A, Ciphertext<A>> {
76 type Boolean = Boolean<A>;
77
78 fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
80 let visibility_bits = match self {
81 Self::Constant(..) => VISIBILITY_CONSTANT,
82 Self::Public(..) => VISIBILITY_PUBLIC,
83 Self::Private(..) => VISIBILITY_PRIVATE,
84 };
85 vec.extend(visibility_bits.iter().map(|&bit| Boolean::constant(bit)));
86 match self {
87 Self::Constant(plaintext) => plaintext.write_bits_le(vec),
88 Self::Public(plaintext) => plaintext.write_bits_le(vec),
89 Self::Private(plaintext) => plaintext.write_bits_le(vec),
90 };
91 }
92
93 fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
95 let visibility_bits = match self {
96 Self::Constant(..) => VISIBILITY_CONSTANT,
97 Self::Public(..) => VISIBILITY_PUBLIC,
98 Self::Private(..) => VISIBILITY_PRIVATE,
99 };
100 vec.extend(visibility_bits.iter().map(|&bit| Boolean::constant(bit)));
101 match self {
102 Self::Constant(plaintext) => plaintext.write_bits_be(vec),
103 Self::Public(plaintext) => plaintext.write_bits_be(vec),
104 Self::Private(plaintext) => plaintext.write_bits_be(vec),
105 };
106 }
107}