snarkvm_circuit_program/data/ciphertext/
mod.rs1mod decrypt;
17mod equal;
18mod from_bits;
19mod from_fields;
20mod num_randomizers;
21mod size_in_fields;
22mod to_bits;
23mod to_fields;
24
25use crate::{Plaintext, Visibility};
26use snarkvm_circuit_network::Aleo;
27use snarkvm_circuit_types::{Boolean, Field, environment::prelude::*};
28
29use core::ops::Deref;
30
31#[derive(Clone)]
32pub struct Ciphertext<A: Aleo>(Vec<Field<A>>);
33
34#[cfg(feature = "console")]
35impl<A: Aleo> Inject for Ciphertext<A> {
36 type Primitive = console::Ciphertext<A::Network>;
37
38 fn new(mode: Mode, ciphertext: Self::Primitive) -> Self {
40 match (*ciphertext).len() <= A::MAX_DATA_SIZE_IN_FIELDS as usize {
42 true => Self(Inject::new(mode, (*ciphertext).to_vec())),
43 false => A::halt("Ciphertext exceeds maximum allowed size"),
44 }
45 }
46}
47
48#[cfg(feature = "console")]
49impl<A: Aleo> Eject for Ciphertext<A> {
50 type Primitive = console::Ciphertext<A::Network>;
51
52 fn eject_mode(&self) -> Mode {
54 self.0.eject_mode()
55 }
56
57 fn eject_value(&self) -> Self::Primitive {
59 match console::FromFields::from_fields(&self.0.eject_value()) {
60 Ok(ciphertext) => ciphertext,
61 Err(error) => A::halt(format!("Failed to eject ciphertext: {error}")),
62 }
63 }
64}
65
66impl<A: Aleo> Deref for Ciphertext<A> {
67 type Target = [Field<A>];
68
69 fn deref(&self) -> &Self::Target {
70 &self.0
71 }
72}