Skip to main content

codec_cbor/
value.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use zeroize::Zeroize;
6
7/// A decoded DAG-CBOR value.
8///
9/// Values retain the movable public enum API. Callers handling sensitive
10/// documents can wrap them in [`zeroize::Zeroizing`] or call [`Zeroize::zeroize`]
11/// when finished; codec-owned temporary values use wiping owners internally.
12#[derive(Debug, Clone, PartialEq)]
13#[non_exhaustive]
14pub enum CborValue {
15    /// CBOR null.
16    Null,
17    /// CBOR boolean.
18    Bool(bool),
19    /// A signed integer within the `i64` range.
20    Int(i64),
21    /// A UTF-8 text string.
22    String(String),
23    /// A byte string.
24    Bytes(Vec<u8>),
25    /// An array of values.
26    Array(Vec<CborValue>),
27    /// A map of text-string keys to values, in canonical key order.
28    Map(Vec<(String, CborValue)>),
29}
30
31// Preserve the public movable enum API while allowing adapters and callers to
32// install a Zeroizing owner for identity-bearing documents.
33impl Zeroize for CborValue {
34    fn zeroize(&mut self) {
35        match self {
36            Self::Null => {}
37            Self::Bool(value) => value.zeroize(),
38            Self::Int(value) => value.zeroize(),
39            Self::String(value) => value.zeroize(),
40            Self::Bytes(value) => value.zeroize(),
41            Self::Array(values) => values.zeroize(),
42            Self::Map(entries) => entries.zeroize(),
43        }
44    }
45}