Repository navigation
refactor(stack-encrypt)!: remove target::legacy #1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4558be4
2c5416d
1bd628f
99af837
4b9b507
410d2ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,9 +292,9 @@ use eql_bindings::Identifier; | |
| let email = Identifier::for_column("members", "email")?; | ||
| let age = Identifier::for_column("members", "age")?; | ||
|
|
||
| // Not on `next` yet: the new traits for EQL types, and a borrowed value | ||
| // and context. Today this needs `target::legacy::EncryptInto`, an owned | ||
| // value, and an owned context. | ||
| // Not on `next` yet: a borrowed value, and a context built with | ||
| // `Scope::new`. Today this needs an owned value and an owned context: | ||
| // `"[email protected]".to_owned().encrypt_into_with_context(&keyset, email.clone())`. | ||
| let by_email: TextEqQuery = "[email protected]" | ||
| .encrypt_into_with_context(&keyset, Scope::new(&email)) | ||
| .await?; | ||
|
|
@@ -402,8 +402,8 @@ use stack_encrypt::json::JsonPlaintext; | |
| let column = Identifier::for_column("customers", "profile")?; | ||
|
|
||
| // Not on `next` yet: the new traits for EQL types, and the public | ||
| // `JsonPlaintext`. Today this needs `target::legacy::EncryptInto`, a | ||
| // `serde_json::Value`, and an owned context. | ||
| // `JsonPlaintext`. Today this needs `keyset.encrypt_as(&value, context)`, | ||
| // a `serde_json::Value`, and an owned context. | ||
| let profile: JsonPlaintext = json!({ "name": "Ada", "age": 35 }).into(); | ||
| let encrypted: JsonTreeDocument = profile | ||
| .encrypt_into_with_context(&keyset, Scope::new(&column)) | ||
|
|
@@ -1867,7 +1867,7 @@ parameter named `aad`. | |
| `'static`, so `&str` does not meet it. A borrowed value needs its own | ||
| bound, and the request borrows the value for as long as it runs. | ||
| - **Done already.** Owned single values (#1404). | ||
| - **Tracked in.** No issue. Issue #1468, open, a Vitamin C buffer type, is adjacent. | ||
| - **Tracked in.** #1569. Issue #1468, open, a Vitamin C buffer type, is adjacent. | ||
| - **Finished when** `keyset.encrypt("secret")` compiles, and a test shows | ||
| that Stack Encrypt wipes its own copies of a borrowed value. | ||
|
|
||
|
|
@@ -1987,8 +1987,8 @@ table. | |
|
|
||
| #### Remove the structural API | ||
|
|
||
| - **What to build.** Remove `EncryptFrom`, `DecryptInto`, `encrypt_as`, and | ||
| the helpers in `target::legacy`. Remove the plan builder: | ||
| - **What to build.** Remove `EncryptFrom`, `DecryptInto`, `encrypt_as` and | ||
| `decrypt_as`. Remove the plan builder: | ||
| `plan/build.rs`, `plan/chain.rs`, `plan/value.rs`, and | ||
| `plan/field_ref.rs`, with `pick!`, `FieldRef`, `Runs`, and `Opens`. | ||
| `Plan::encryption` moves into `Planned` (ADR-0007, amended 9 November | ||
|
|
@@ -2008,10 +2008,13 @@ table. | |
| and the checks read them. The dynamic path no longer uses the plan | ||
| builder. Those functions do not yet build a `Planned`: they run the | ||
| lowering themselves. That inversion, the builder, the chain, the old | ||
| traits and `Label` are still to be removed. | ||
| traits and `Label` are still to be removed. The helpers in | ||
| `target::legacy` are removed, in the fourth pull request for #1488. | ||
| Their callers use `encrypt_as` and `decrypt_as` until those go too. | ||
| - **Tracked in.** Issue #1488 is open. Its first pull request is the | ||
| lowering. Its second replaces `CipherScope` and `dynamic::Scope` with | ||
| `CipherRef`. The removals follow. | ||
| `CipherRef`. Its third hides `ExpectedContext`. Its fourth removes | ||
| `target::legacy`. The other removals follow. | ||
| - **Finished when** the old API is gone, and every consumer uses the new | ||
| API. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,6 +214,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
| jiff has no leap seconds, so the error now says only what is wrong: | ||
| `Timestamp::new` was given nanoseconds of one second or more. | ||
|
|
||
| - **`target::legacy` is removed** (#1488). It held two traits, | ||
| implemented for every type, that gave the structural API a second | ||
| call syntax: `value.encrypt_into(&keyset)`, | ||
| `value.encrypt_into_with_context(&keyset, context)`, | ||
| `Target::encrypt_from(&value, &keyset, context)`, | ||
| `stored.decrypt_into(&cipher, context)`, `P::decrypt_from(stored, &cipher)` | ||
| and `P::decrypt_from_with_context(stored, &cipher, context)`. Their | ||
| names were the same as the owned traits' `EncryptInto` and | ||
| `DecryptFrom`, but they borrowed the plaintext. | ||
| - To upgrade a type that implements `EncryptTarget` or | ||
| `DecryptSource`, use the owned traits. They take the plaintext by | ||
| value. | ||
| - To upgrade a type that implements only `EncryptFrom` or | ||
| `DecryptInto`, call the cipher. The context is `T::Context`, so | ||
| convert it with `into()`: | ||
|
|
||
| | Removed call | Replacement | | ||
| | --- | --- | | ||
| | `value.encrypt_into(&keyset)` | `keyset.encrypt_as(&value, Default::default())` | | ||
| | `value.encrypt_into_with_context(&keyset, context)` | `keyset.encrypt_as(&value, context.into())` | | ||
| | `Target::encrypt_from(&value, &keyset, context)` | `keyset.encrypt_as::<_, Target>(&value, context.into())` | | ||
| | `stored.decrypt_into(&cipher, context)` | `cipher.decrypt_as(stored, context.into())` | | ||
| | `P::decrypt_from(stored, &cipher)` | `cipher.decrypt_as::<P, _>(stored, Default::default())` | | ||
| | `P::decrypt_from_with_context(stored, &cipher, context)` | `cipher.decrypt_as::<P, _>(stored, context.into())` | | ||
|
Comment on lines
+238
to
+240
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note the The removed
|
||
|
|
||
| `encrypt_as` does not name the target, so name it with a type | ||
| annotation on the result or with the turbofish shown. | ||
| - If `value` is already a reference, pass it as it is: | ||
| `keyset.encrypt_as(value, ..)`. The removed methods took the value | ||
| through method-call autoref, so a `&String` receiver encrypted a | ||
| `String`. `encrypt_as(&value, ..)` on a `&String` encrypts a | ||
| `&String` instead. Into a derived record that is a compile error. | ||
| Into `StackCipherText` it compiles, because that target accepts any | ||
| `Encrypt` source. | ||
|
|
||
| - **`target::ExpectedContext` is no longer part of the API** (#1488). It | ||
| is the check that a `#[stash(context_field)]` record runs on decrypt: | ||
| the stored context must equal the one the caller expects, if the caller | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| //! Searchable Encrypted Metadata, leaf by leaf. | ||
| //! | ||
| //! Shows each index-term primitive on its own through the target-directed | ||
| //! `encrypt_into` API: equality terms (exact match), match terms (full-text | ||
| //! owned `encrypt_into` API: equality terms (exact match), match terms (full-text | ||
| //! containment), and ORE/OPE terms (range queries) — all generated locally | ||
| //! from a deterministic per-keyset index key, then compared the way a server | ||
| //! would compare them: without ever seeing a plaintext. | ||
|
|
@@ -20,8 +20,8 @@ | |
|
|
||
| use stack_encrypt::sem::{EqualityTerm, MatchTerms, OreTerm}; | ||
|
|
||
| use stack_encrypt::target::legacy::EncryptInto; | ||
| use stack_encrypt::{nonempty, EncryptFrom, StackCipher, StackCipherText}; | ||
| use stack_encrypt::target::EncryptTarget; | ||
| use stack_encrypt::{nonempty, EncryptInto, StackCipher, StackCipherText}; | ||
|
|
||
| #[tokio::main(flavor = "current_thread")] | ||
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
|
|
@@ -44,17 +44,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| // field: the same | ||
| // value indexed under another field can never produce a colliding term. | ||
|
|
||
| let stored: EqualityTerm = "[email protected]" | ||
| let stored: EqualityTerm = String::from("[email protected]") | ||
|
coderdan marked this conversation as resolved.
Resolved
|
||
| .encrypt_into_with_context(&terms, nonempty!("users").with("email")) | ||
| .await?; | ||
|
|
||
| let hit: EqualityTerm = "[email protected]" | ||
| let hit: EqualityTerm = String::from("[email protected]") | ||
| .encrypt_into_with_context(&terms, nonempty!("users").with("email")) | ||
| .await?; | ||
| let miss: EqualityTerm = "[email protected]" | ||
| let miss: EqualityTerm = String::from("[email protected]") | ||
| .encrypt_into_with_context(&terms, nonempty!("users").with("email")) | ||
| .await?; | ||
| let wrong_field: EqualityTerm = "[email protected]" | ||
| let wrong_field: EqualityTerm = String::from("[email protected]") | ||
| .encrypt_into_with_context(&terms, nonempty!("users").with("name")) | ||
| .await?; | ||
|
|
||
|
|
@@ -127,10 +127,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| // | ||
| // Leaf by leaf is the query side. On the write side a field is stored | ||
| // as *every* term it needs beside its ciphertext, in one shape: derive | ||
| // `EncryptFrom` for that shape and each field of it is derived from the | ||
| // `EncryptTarget` for that shape and each field of it is derived from the | ||
| // one value under the one context — byte-identical to the leaves above, | ||
| // so a probe built leaf by leaf finds what the record stored. | ||
| #[derive(EncryptFrom)] | ||
| #[derive(EncryptTarget)] | ||
| #[stash(plaintext = String)] | ||
| struct SearchableEmail { | ||
| c: StackCipherText, | ||
|
|
@@ -164,7 +164,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| .encrypt_into_with_context(&terms, nonempty!("users").with("email")) | ||
| .await? | ||
| ); | ||
| let _ = record.c; // the ciphertext, opened with `decrypt_into` under the same context | ||
| let _ = record.c; // the ciphertext, opened with `decrypt_from_with_context` under the same context | ||
|
|
||
| Ok(()) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.