1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-3.0-or-later
pub mod fb128;

use crate::{BlockOps, Encode, FieldOps};
use crypto_bigint::{ArrayEncoding, Bounded, RandomMod};
use std::sync::RwLock;
use std::marker::Sync;

/// The False Bottom Object holds the ciphertext and the keybase. The provided type aliases can be used to pick a block size.
pub struct FBObj<T> {
	pub(crate) c: RwLock<Vec<T>>,
	pub(crate) r: Vec<T>,
}

pub trait FBObjTrait<T> {
	fn cipher(&self) -> &RwLock<Vec<T>>;
	fn keybase(&self) -> &Vec<T>;
}

impl<T> FBObjTrait<T> for FBObj<T> {
	fn cipher(&self) -> &RwLock<Vec<T>> {
		&self.c
	}
	fn keybase(&self) -> &Vec<T> {
		&self.r
	}
}

impl<T> BlockOps<T> for FBObj<T>
where
	T: FieldOps + RandomMod + Send + Sync
{}

impl<T> Encode<T> for FBObj<T>
where
	T: ArrayEncoding + Bounded
{}