snarkvm_circuit_program/data/record/entry/
to_bits.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18impl<A: Aleo> ToBits for Entry<A, Plaintext<A>> {
19    type Boolean = Boolean<A>;
20
21    /// Returns this entry as a list of **little-endian** bits.
22    fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
23        match self {
24            Self::Constant(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(false)]),
25            Self::Public(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(true)]),
26            Self::Private(..) => vec.extend_from_slice(&[Boolean::constant(true), Boolean::constant(false)]),
27        };
28        match self {
29            Self::Constant(plaintext) => plaintext.write_bits_le(vec),
30            Self::Public(plaintext) => plaintext.write_bits_le(vec),
31            Self::Private(plaintext) => plaintext.write_bits_le(vec),
32        };
33    }
34
35    /// Returns this entry as a list of **big-endian** bits.
36    fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
37        match self {
38            Self::Constant(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(false)]),
39            Self::Public(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(true)]),
40            Self::Private(..) => vec.extend_from_slice(&[Boolean::constant(true), Boolean::constant(false)]),
41        };
42        match self {
43            Self::Constant(plaintext) => plaintext.write_bits_be(vec),
44            Self::Public(plaintext) => plaintext.write_bits_be(vec),
45            Self::Private(plaintext) => plaintext.write_bits_be(vec),
46        };
47    }
48}
49
50impl<A: Aleo> ToBits for Entry<A, Ciphertext<A>> {
51    type Boolean = Boolean<A>;
52
53    /// Returns this entry as a list of **little-endian** bits.
54    fn write_bits_le(&self, vec: &mut Vec<Boolean<A>>) {
55        match self {
56            Self::Constant(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(false)]),
57            Self::Public(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(true)]),
58            Self::Private(..) => vec.extend_from_slice(&[Boolean::constant(true), Boolean::constant(false)]),
59        };
60        match self {
61            Self::Constant(plaintext) => plaintext.write_bits_le(vec),
62            Self::Public(plaintext) => plaintext.write_bits_le(vec),
63            Self::Private(plaintext) => plaintext.write_bits_le(vec),
64        };
65    }
66
67    /// Returns this entry as a list of **big-endian** bits.
68    fn write_bits_be(&self, vec: &mut Vec<Boolean<A>>) {
69        match self {
70            Self::Constant(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(false)]),
71            Self::Public(..) => vec.extend_from_slice(&[Boolean::constant(false), Boolean::constant(true)]),
72            Self::Private(..) => vec.extend_from_slice(&[Boolean::constant(true), Boolean::constant(false)]),
73        };
74        match self {
75            Self::Constant(plaintext) => plaintext.write_bits_be(vec),
76            Self::Public(plaintext) => plaintext.write_bits_be(vec),
77            Self::Private(plaintext) => plaintext.write_bits_be(vec),
78        };
79    }
80}