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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
//! Content-addressed bytes, kept out of the chain.
//!
//! The journal refuses a record over [`Record::MAX_RECORD_BYTES`], and this is
//! the other half of that refusal: somewhere for the bytes to go. The pattern is
//! the field's — Temporal calls it a claim check, offloading payloads above a
//! threshold and passing a reference through the event history instead — with
//! one difference that matters here.
//!
//! **The reference is the digest.** Temporal's token identifies a payload;
//! a digest *is* the payload's identity. So the hash chain still commits to the
//! exact bytes even though it does not contain them: an auditor who fetches a
//! blob can check it against the digest the chain already signed, and a swapped
//! blob is as detectable as a rewritten record. A reference that merely pointed
//! at mutable storage would move the tamper-evidence boundary without saying so.
//!
//! Three properties follow, and each is a rule rather than a nicety:
//!
//! * **The store computes the digest, never the caller.** A caller who supplied
//! both bytes and digest could supply a pair that does not match, and every
//! later verification would compare a blob against a claim rather than a fact.
//! * **Reads verify before returning.** Storage is the least trusted thing here
//! — it is the part an operator can reach with a text editor.
//! * **Writes are idempotent by construction.** Same bytes, same address; there
//! is nothing to race and no transaction to need. That is precisely why an
//! object store is the right shape for this and the wrong shape for the
//! journal, which needs ordered scans and multi-key atomicity.
//!
//! [`Record::MAX_RECORD_BYTES`]: crate::journal::Record::MAX_RECORD_BYTES
use Debug;
use async_trait;
use crate;
pub use ;
pub use MemoryBlobs;
pub use ;
/// What can go wrong reaching content-addressed storage.
/// Why an erasure did not happen.
///
/// Separate from [`BlobError`], whose every variant describes something that
/// already happened to some bytes. An erasure verb is not a blob operation — it
/// walks a case, tombstones each blob and destroys a key scope — and it can
/// refuse outright, which is not a state any reader of a blob can observe.
/// Bytes addressed by their own hash.
///
/// # Two roles, and only one of them answers every method
///
/// Most of this trait is the contract every implementation carries: `put`,
/// `get`, `expire`, `has`, and the rule that an expired address stays expired.
///
/// [`put_at`](Self::put_at) and [`get_raw`](Self::get_raw) are the **envelope
/// pair**, and they belong to a *backing* store — one something may seal onto.
/// A sealing decorator refuses both on purpose
/// ([`EncryptedBlobs`](crate::keyring::EncryptedBlobs) does), because exposing
/// them through it is an unsealed side door: a caller reaching `put_at` on a
/// deployment that asked for sealing writes plaintext under a scope whose
/// erasure can never reach it. So a store that refuses the pair is not
/// incomplete, and a battery demanding it of everything would fail the one
/// implementation whose refusal is the guarantee — which is why
/// `testkit::conformance_blob` has two entry points rather than one.
///
/// Stated here rather than only at the decorator that refuses, because the
/// reader who needs it is writing the *next* implementation.
/// Expire every blob a case produced.
///
/// The erasure unit, because a case is what a request actually names — nobody
/// asks to forget a digest. Each blob is tombstoned with the same reason, so a
/// later read says *expired, on this date, for this reason* rather than
/// *missing*, and the journal still proves what happened.
///
/// `tenant` derives the addresses to tombstone: blobs live at
/// [`unit_address`]`(erasure_scope(tenant, case), digest)`, so this erasure
/// reaches exactly this case's copies — [`ScopedBlobs`] carries the argument
/// for why the erasure unit leads the address.
///
/// Returns how many blobs were expired. Zero is an ordinary answer: a case that
/// stored nothing has nothing to forget, and reporting that as an error would
/// make the caller special-case the common path.
///
/// What this does **not** touch is the journal. Records are append-only by
/// design, so personal data written into one cannot be removed — keep it out of
/// records rather than expecting erasure to reach it.
///
/// `blobs` is optional because the erasure unit is the **key scope**, and a
/// plane that seals its journal with a key ring and stores no blobs at all is
/// an ordinary shape. Refusing to erase such a case for want of a store to
/// tombstone would leave the one act that reaches every copy undone because a
/// second, lesser act had nowhere to land. With no store the linked digests
/// are counted and left; on a sealed plane their bytes become unreadable by
/// the key destruction below, and a later drill reads them as *erased by
/// design* through the key rather than through a tombstone.
///
/// # Errors
///
/// [`EraseError::Store`] carrying [`StoreError::NotFound`](crate::core::StoreError::NotFound)
/// if the case does not exist, and an error if the case's blob list cannot be
/// read or a blob cannot be expired.
pub async
/// Destroy the erasure scope of a run that belongs to no case.
///
/// The counterpart of [`erase_case`], for the unit that call can never reach:
/// a record bound to no case seals its payloads under `tenant/<run>` (see
/// `SealedJournal`), and `erase_case` — which walks a case's blobs and
/// destroys the *case* scope — was the only erasure verb, so a case-less run's
/// sealed payloads had no erasure path at all. This is the missing verb: it
/// destroys exactly the `tenant/<run>` scope, and with it every payload sealed
/// under that run — in the live store, every replica, and every backup ever
/// taken, because what is destroyed was never in them.
///
/// **The erasure unit is the run.** There is no blob traversal here because
/// blob writes are scoped to a run's case; a run with no case links no blobs
/// through the case layer, and anything sealed for it lives in its journal
/// payloads. The journal's records — chain, routing fields, the fact the run
/// happened — remain readable and verifiable, which is the whole design: the
/// chain committed to ciphertext.
///
/// Idempotent as [`KeyRing::destroy`](crate::keyring::KeyRing::destroy) is:
/// the first destruction stands, so a retry cannot rewrite when or why the
/// data went.
///
/// # Errors
///
/// If the key ring cannot be reached.
///
/// **A case-less run cannot be held.** A legal hold is placed on a *matter*,
/// and this verb exists precisely for the run that belongs to none — so there
/// is no row to hold and nothing here consults one. A deployment that needs a
/// run preserved binds it to a case, which is also what gives it an obligation
/// trail; that is the documented limit rather than a second hold mechanism
/// keyed by run.
pub async
/// Re-state a blob failure in the vocabulary a step is refused in.
///
/// Only one variant changes shape, and it is the one that is not a fault:
/// [`BlobError::Expired`] on a *write* means the address was erased, which is a
/// rule rather than an outage and must not be classified as one. Everything
/// else keeps its own words inside a backend error, because to a caller holding
/// a step there is nothing else to do about them.
pub
/// [`refusal`] under a name a test may call.
///
/// The classification is the half of the rule a caller sees, and it is not
/// otherwise reachable: `StepCtx::store_blob` is the only in-crate caller and
/// its own error is wrapped twice by the time a test could read it.
/// Check fetched bytes against the address they came from.
///
/// Shared by every backend so the verification cannot be implemented slightly
/// differently — or omitted — by one of them.
pub