Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions languages/golang/encrypt/guest/tests/leak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ fn vitur(status: u16) -> ViturRequestError {
#[derive(Default)]
struct Failing(FakeDataKeySource);

impl stack_kms::KeySourceKind for Failing {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Failing {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions languages/golang/encrypt/guest/tests/native_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ struct Counting {
retrieve_calls: AtomicUsize,
}

impl stack_kms::KeySourceKind for Counting {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Counting {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/eql/tests/encryption/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub struct RecordingKeySource {
inner: FakeDataKeySource,
calls: Arc<Mutex<Calls>>,
}
impl stack_kms::KeySourceKind for RecordingKeySource {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for RecordingKeySource {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/eql/tests/encryption/tests/heap_hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ impl Stalling {
}
}

impl stack_kms::KeySourceKind for Stalling {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Stalling {
async fn generate_keys(
&self,
Expand Down
15 changes: 15 additions & 0 deletions packages/stack-encrypt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking

- **A key source of your own states its kind.** `kms::DataKeySource`,
`kms::IndexKeySource` and `kms::CredentialKeySource` each require
`kms::KeySourceKind`, so that a type cannot be both kinds of key source.
To migrate, add one impl to each key source you wrote, such as a test
double. A cipher built with `auth_strategy(..)` or over
`kms::StackKms`, `kms::FakeDataKeySource` or
`kms::FakeCredentialKeySource` needs no change.

```rust
impl stack_encrypt::kms::KeySourceKind for MyKeySource {
// `kms::CredentialPerCall` for a `CredentialKeySource`.
type Kind = stack_encrypt::kms::OwnIdentity;
}
```

- **`.kms(source)` returns a builder in its own state** (#1708). This
follows from telling the two kinds of key source apart in the types
(`KeySource`). `StackCipher::builder().kms(source)` returns a
Expand Down
4 changes: 3 additions & 1 deletion packages/stack-encrypt/src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ mod sealed {
/// compiler works it out from the key source.
///
/// Sealed: it is implemented for every key source of either kind, and for
/// nothing else. To supply a key source, implement the traits of its kind.
/// nothing else. To supply a key source, implement the traits of its kind,
/// and state the kind ([`KeySourceKind`](stack_kms::KeySourceKind)). A key
/// source states one kind, so it is never both. That rule is Stack KMS's.
pub trait KeySource<I>: sealed::Sealed<I> {
/// The identity to load the default keyset as when the cipher is
/// built, when no caller is present: the key source's own, or `None`
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/src/dynamic/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,10 @@ mod tests {
retrieve_calls: AtomicUsize,
}

impl stack_kms::KeySourceKind for Counting {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Counting {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/src/target/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,10 @@ mod tests {
}
}

impl stack_kms::KeySourceKind for CountingSource {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for CountingSource {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/tests/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl RecordingSource {
}
}

impl stack_encrypt::kms::KeySourceKind for RecordingSource {
type Kind = stack_encrypt::kms::OwnIdentity;
}

impl DataKeySource for RecordingSource {
async fn generate_keys(
&self,
Expand Down
8 changes: 8 additions & 0 deletions packages/stack-encrypt/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ impl<S> CountingSource<S> {
}
}

impl<S> stack_kms::KeySourceKind for CountingSource<S> {
type Kind = stack_kms::OwnIdentity;
}

impl<S: DataKeySource + Sync> DataKeySource for CountingSource<S> {
async fn generate_keys(
&self,
Expand Down Expand Up @@ -228,6 +232,10 @@ impl RecordingSource {
}
}

impl stack_kms::KeySourceKind for RecordingSource {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for RecordingSource {
async fn generate_keys(
&self,
Expand Down
8 changes: 8 additions & 0 deletions packages/stack-encrypt/tests/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ fn is_refusal(error: &Error, why: &str) -> bool {
#[derive(Clone)]
struct OwnIdentity(Source);

impl stack_encrypt::kms::KeySourceKind for OwnIdentity {
type Kind = stack_encrypt::kms::OwnIdentity;
}

impl DataKeySource for OwnIdentity {
async fn generate_keys(
&self,
Expand Down Expand Up @@ -219,6 +223,10 @@ impl IndexKeySource for OwnIdentity {
}
}

impl stack_encrypt::kms::KeySourceKind for Source {
type Kind = stack_encrypt::kms::CredentialPerCall;
}

impl CredentialKeySource for Source {
async fn generate_keys_with_credential(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/tests/frozen_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ async fn sealed_value_keyset_id_is_authenticated() {
/// saturated length field that `from_bytes` no longer inverts.
struct OversizedTagSource(FakeDataKeySource);

impl stack_kms::KeySourceKind for OversizedTagSource {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for OversizedTagSource {
async fn generate_keys(
&self,
Expand Down
8 changes: 8 additions & 0 deletions packages/stack-encrypt/tests/heap_hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,10 @@ mod cancellation {
}
}

impl stack_kms::KeySourceKind for Stalling {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Stalling {
async fn generate_keys(
&self,
Expand Down Expand Up @@ -2185,6 +2189,10 @@ mod json_index {
.copy_from_slice(key.key());
}

impl stack_kms::KeySourceKind for Recorded {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Recorded {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/tests/json_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ impl Shared {
}
}

impl stack_kms::KeySourceKind for Shared {
type Kind = stack_kms::CredentialPerCall;
}

impl stack_kms::CredentialKeySource for Shared {
async fn generate_keys_with_credential(
&self,
Expand Down
8 changes: 8 additions & 0 deletions packages/stack-encrypt/tests/keysets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ impl Observed {
}
}

impl stack_kms::KeySourceKind for Observed {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Observed {
async fn generate_keys(
&self,
Expand Down Expand Up @@ -850,6 +854,10 @@ impl Reader {
}
}

impl stack_kms::KeySourceKind for Reader {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Reader {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/tests/lifecycle_conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct Source {
observed: Arc<Observations>,
}

impl stack_kms::KeySourceKind for Source {
type Kind = stack_kms::OwnIdentity;
}

impl DataKeySource for Source {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/tests/opaque_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ const FIXED_TAG: &[u8] = b"fixed-key-tag";
/// ciphertext sealed once can be pinned and opened by any later build.
struct FixedKeySource(stack_kms::FakeDataKeySource);

impl stack_kms::KeySourceKind for FixedKeySource {
type Kind = stack_kms::OwnIdentity;
}

impl stack_kms::DataKeySource for FixedKeySource {
async fn generate_keys(
&self,
Expand Down
4 changes: 4 additions & 0 deletions packages/stack-encrypt/tests/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ struct FixedKeySource(stack_kms::FakeDataKeySource);
const FIXED_KEY: [u8; 32] = *b"fixed-data-key-for-pinned-leaf!!";
const FIXED_IV: [u8; 16] = *b"fixed-iv-pinned!";
const FIXED_TAG: &[u8] = b"fixed-key-tag";
impl stack_kms::KeySourceKind for FixedKeySource {
type Kind = stack_kms::OwnIdentity;
}

impl stack_kms::DataKeySource for FixedKeySource {
async fn generate_keys(
&self,
Expand Down
17 changes: 17 additions & 0 deletions packages/stack-kms/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Breaking

- Requires stack-auth 0.44 and stack-profile 0.44.
- A key source states which kind it is, with the new `KeySourceKind`
trait. `DataKeySource` and `IndexKeySource` require the kind
`OwnIdentity`, and `CredentialKeySource` requires the kind
`CredentialPerCall`. A type states one kind, so a key source of both
kinds does not compile. Before, only the docs said a key source is one
kind or the other. To migrate, add one impl to each key source of your
own, such as a test double:

```rust
impl stack_kms::KeySourceKind for MyKeySource {
type Kind = stack_kms::OwnIdentity;
}
```

`StackKms` needs no change: its kind is the kind of its auth strategy
(`stack_auth::StrategyKind`). The test doubles of this crate state
theirs. Re-exports `CredentialPerCall` beside `OwnIdentity`.

### Features

Expand Down
Loading
Loading