Skip to content

Commit 0cb8db1

Browse files
author
Bennett Hardwick
committed
Add helpers for sealer records
1 parent c3dfaa1 commit 0cb8db1

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/crypto/sealer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Sealer {
213213

214214
table_entries.push((
215215
PrimaryKeyParts { pk, sk },
216-
record.unsealed.unprotected(),
216+
record.unsealed.unprotected().clone(),
217217
terms,
218218
));
219219
}

src/crypto/unsealed.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ impl Unsealed {
3737
}
3838
}
3939

40+
pub fn protected(&self) -> &HashMap<String, (Plaintext, String)> {
41+
&self.protected
42+
}
43+
44+
pub fn unprotected(&self) -> &HashMap<String, TableAttribute> {
45+
&self.unprotected
46+
}
47+
4048
pub fn get_protected(&self, name: &str) -> Result<&Plaintext, SealError> {
4149
let (plaintext, _) = self
4250
.protected
@@ -63,10 +71,6 @@ impl Unsealed {
6371
self.unprotected.insert(name.into(), attribute);
6472
}
6573

66-
pub(crate) fn unprotected(&self) -> HashMap<String, TableAttribute> {
67-
self.unprotected.clone()
68-
}
69-
7074
/// Remove and return a protected value along with its descriptor.
7175
pub(crate) fn remove_protected_with_descriptor(
7276
&mut self,

src/encrypted_table/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cipherstash_client::{
1919
service_credentials::{ServiceCredentials, ServiceToken},
2020
Credentials,
2121
},
22-
encryption::Encryption,
22+
encryption::{Encryption, Plaintext},
2323
zero_kms::ZeroKMS,
2424
};
2525
use log::info;
@@ -137,6 +137,24 @@ impl PreparedRecord {
137137
}
138138
}
139139

140+
/// Get all the [`Plaintext`] protected attributes from the [`PreparedRecord`]
141+
pub fn protected(&self) -> impl Iterator<Item = (&str, &Plaintext)> {
142+
self.sealer
143+
.unsealed
144+
.protected()
145+
.iter()
146+
.map(|(key, (plaintext, _descriptor))| (key.as_str(), plaintext))
147+
}
148+
149+
/// Get all the unprotected attributes from the [`PreparedRecord`]
150+
pub fn unprotected(&self) -> impl Iterator<Item = (&str, &TableAttribute)> {
151+
self.sealer
152+
.unsealed
153+
.unprotected()
154+
.iter()
155+
.map(|(key, attr)| (key.as_str(), attr))
156+
}
157+
140158
pub fn prepare_record<R>(record: R) -> Result<Self, SealError>
141159
where
142160
R: Searchable + Identifiable,

0 commit comments

Comments
 (0)