|
148 | 148 | //! |
149 | 149 | //! Decryption **authenticates before it decodes**. The leaf opens first, |
150 | 150 | //! under its key and context; only then does the profile's reader see the |
151 | | -//! bytes. So the errors tell three things apart: |
152 | | -//! |
153 | | -//! - [`Error::Aead`]: the leaf did not open. Wrong key, wrong context, or |
154 | | -//! altered bytes; the blob was never looked at. |
| 151 | +//! bytes. A context other than the one the blob was sealed under is |
| 152 | +//! normally refused before that: ZeroKMS binds each data key to its |
| 153 | +//! context's descriptor and denies the retrieve, so it surfaces as |
| 154 | +//! [`Error::Kms`] and nothing is decrypted. Past key retrieval, the errors |
| 155 | +//! tell three things apart: |
| 156 | +//! |
| 157 | +//! - [`Error::Aead`]: the leaf did not open. Altered bytes, the wrong key, |
| 158 | +//! or a wrong context under a key source that ignores descriptors |
| 159 | +//! (`FakeDataKeySource`, in tests); the blob was never looked at. |
155 | 160 | //! - [`Error::OpenedType`]: the leaf opened but is not a bytes leaf: it was |
156 | 161 | //! sealed as a `String` or an integer, say, not as a blob. |
157 | 162 | //! - [`Error::Blob`]: the leaf opened as bytes and they are not a blob this |
|
160 | 165 | //! of version 1 ([`BlobError::Malformed`]), or a well-formed blob that is |
161 | 166 | //! not a `T` ([`BlobError::Mismatch`]). |
162 | 167 | //! |
163 | | -//! All three are refusals of an authentic ciphertext, so an `Error::Blob` |
164 | | -//! never says the data was tampered with; it says the data was written as |
165 | | -//! something else. The whole blob is validated before `T`'s `Deserialize` |
| 168 | +//! [`Error::OpenedType`] and [`Error::Blob`] are refusals of an authentic |
| 169 | +//! ciphertext, so neither says the data was tampered with; each says the |
| 170 | +//! data was written as something else. Only [`Error::Aead`] (or |
| 171 | +//! [`Error::Kms`]) leaves the ciphertext's authenticity unestablished. The whole blob is validated before `T`'s `Deserialize` |
166 | 172 | //! sees any of it: every length is checked against the end of the blob, so |
167 | 173 | //! a forged length allocates nothing, and a `Deserialize` impl never builds |
168 | 174 | //! part of a value from a malformed blob. No refusal names a value or a map |
|
238 | 244 | //! with its marker; both readers read either form). |
239 | 245 | //! |
240 | 246 | //! [`Error::Aead`]: crate::Error::Aead |
| 247 | +//! [`Error::Kms`]: crate::Error::Kms |
241 | 248 | //! [`Error::OpenedType`]: crate::Error::OpenedType |
242 | 249 | //! [`Error::Blob`]: crate::Error::Blob |
243 | 250 | //! [`KeysetCipher::encrypt`]: crate::KeysetCipher::encrypt |
|
0 commit comments