@@ -4,16 +4,12 @@ mod sealed;
44mod sealer;
55mod unsealed;
66use crate :: {
7- traits:: { PrimaryKeyError , PrimaryKeyParts , ReadConversionError , WriteConversionError } ,
8- Identifiable , IndexType , PrimaryKey ,
7+ traits:: { PrimaryKeyError , PrimaryKeyParts , ReadConversionError , WriteConversionError } , Identifiable , IndexType , PrimaryKey
98} ;
109use cipherstash_client:: {
11- credentials:: { service_credentials:: ServiceToken , Credentials } ,
1210 encryption:: {
13- compound_indexer:: { CompoundIndex , ExactIndex } ,
14- Encryption , EncryptionError , Plaintext , TypeParseError ,
15- } ,
16- zerokms:: Error as ZeroKmsError ,
11+ EncryptionError , TypeParseError
12+ } , zerokms
1713} ;
1814use miette:: Diagnostic ;
1915use std:: borrow:: Cow ;
@@ -47,15 +43,16 @@ pub enum SealError {
4743 #[ error( "Assertion failed: {0}" ) ]
4844 AssertionFailed ( String ) ,
4945
50- // Note that we don't expose the specific error type here
51- // so as to avoid leaking any information
5246 #[ error( transparent) ]
53- EncryptionError ( #[ from] EncryptionError ) ,
47+ //#[diagnostic(transparent)] // TODO
48+ CryptoError ( #[ from] zerokms:: Error ) ,
5449
50+ /// Error resulting from Indexing in `cipherstash_client::encryption::compound_indexer`
5551 #[ error( transparent) ]
56- ZeroKmsError ( #[ from] ZeroKmsError ) ,
52+ IndexError ( #[ from] EncryptionError ) ,
5753}
5854
55+ // TODO: Possibly remove this
5956#[ derive( Error , Debug ) ]
6057pub enum CryptoError {
6158 #[ error( "EncryptionError: {0}" ) ]
@@ -94,31 +91,64 @@ pub(crate) fn all_index_keys<'a>(
9491 . collect ( )
9592}
9693
97- /// Use a CipherStash [`ExactIndex`] to take the HMAC of a string with a provided salt
94+ /* / // Use a CipherStash [`ExactIndex`] to take the HMAC of a string with a provided salt
9895///
9996/// This value is used for term index keys and "encrypted" partition / sort keys
100- pub fn hmac (
97+ pub fn prf (
10198 value: &str,
10299 salt: Option<&str>,
103- cipher : & Encryption < impl Credentials < Token = ServiceToken > > ,
100+ cipher: &Cipher,
101+ // TODO: Pass a DatasetWithRootKey (use a Protected)
102+ root_key: [u8; 32],
104103) -> Result<Vec<u8>, EncryptionError> {
105104 let plaintext = Plaintext::Utf8Str(Some(value.to_string()));
106105 let index = CompoundIndex::new(ExactIndex::new(vec![]));
107106
108- cipher
109- . compound_index (
110- & index,
111- plaintext,
112- // passing None here results in no terms so pass an empty string
113- Some ( salt. unwrap_or ( "" ) ) ,
114- 32 ,
115- ) ?
107+ // passing None here results in no terms so pass an empty string
108+ let salt = salt.unwrap_or("");
109+ let accumulator = Accumulator::from_salt(salt);
110+
111+ index
112+ .compose_index(root_key, plaintext.into(), accumulator)?
113+ // TODO: Use a constant for the 32
114+ .truncate(32)
115+ .map(IndexTerm::from)?
116116 .as_binary()
117117 .ok_or(EncryptionError::IndexingError(
118118 "Invalid term type".to_string(),
119119 ))
120+ } */
121+
122+ /*// FIXME: Don't use the root key here
123+ pub fn query_compound_prf<I>(index: I, plaintext: ComposablePlaintext, info: String, root_key: [u8; 32]) -> Result<IndexTerm, SealError> where I: ComposableIndex + Send {
124+ let index = CompoundIndex::new(index);
125+ let accumulator = Accumulator::from_salt(info);
126+
127+ index
128+ .compose_query(root_key, plaintext, accumulator)?
129+ .exactly_one()
130+ // FIXME: Don't use a magic number
131+ .and_then(|term| term.truncate(12))
132+ .and_then(|term| IndexTerm::try_from(term))
133+ .map_err(EncryptionError::from)
134+ .map_err(SealError::from)
120135}
121136
137+ // FIXME: Don't use the root key here
138+ pub fn compound_prf<I>(index: I, plaintext: ComposablePlaintext, info: String, root_key: [u8; 32]) -> Result<IndexTerm, SealError> where I: ComposableIndex + Send {
139+ let index = CompoundIndex::new(index);
140+ let accumulator = Accumulator::from_salt(info);
141+
142+ let term = index
143+ .compose_index(root_key, plaintext, accumulator)?
144+ // FIXME: Don't use a magic number
145+ .truncate(12)
146+ .map_err(EncryptionError::from)?;
147+
148+ // Saftey: This conversion is Infallible
149+ Ok(IndexTerm::try_from(term).unwrap())
150+ } */
151+
122152// Contains all the necessary information to encrypt the primary key pair
123153#[ derive( Clone ) ]
124154pub struct PreparedPrimaryKey {
0 commit comments