pub struct ClaimSet { /* private fields */ }Expand description
A namespace-keyed set of claims.
The outer key is a namespace (e.g., "org.iso.18013.5.1" for mdoc,
"" or "vc" for flat formats like SD-JWT and W3C VC). The inner map
holds claim name to value pairs.
§Examples
use baseid_core::claims::ClaimSet;
use serde_json::json;
let mut claims = ClaimSet::new();
claims.insert("", "given_name", json!("Alice"));
claims.insert("", "family_name", json!("Smith"));
claims.insert("", "birth_date", json!("1990-01-15"));
assert_eq!(claims.get("", "given_name"), Some(&json!("Alice")));Implementations§
Source§impl ClaimSet
impl ClaimSet
Sourcepub fn insert(&mut self, namespace: &str, name: &str, value: Value)
pub fn insert(&mut self, namespace: &str, name: &str, value: Value)
Insert a claim into the given namespace.
Sourcepub fn get(&self, namespace: &str, name: &str) -> Option<&Value>
pub fn get(&self, namespace: &str, name: &str) -> Option<&Value>
Get a claim value by namespace and name.
Sourcepub fn namespaces(
&self,
) -> impl Iterator<Item = (&str, &BTreeMap<String, Value>)>
pub fn namespaces( &self, ) -> impl Iterator<Item = (&str, &BTreeMap<String, Value>)>
Iterate over all namespaces and their claims.
Sourcepub fn namespace(&self, ns: &str) -> Option<&BTreeMap<String, Value>>
pub fn namespace(&self, ns: &str) -> Option<&BTreeMap<String, Value>>
Get claims in a specific namespace.
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Convert flat-namespace claims to a serde_json::Value object.
If a default namespace ("") exists, its claims are returned as a
flat JSON object. Otherwise, namespaces are nested.
Sourcepub fn to_json_flat(&self) -> Option<Value>
pub fn to_json_flat(&self) -> Option<Value>
Convert claims in the default namespace to a flat JSON object.
Returns None if there is no default namespace ("").
Claims in other namespaces are ignored.
Sourcepub fn to_json_namespaced(&self) -> Value
pub fn to_json_namespaced(&self) -> Value
Convert the full claim set to a namespaced JSON object.
Always returns {"namespace": {"claim": value, ...}, ...} regardless
of how many namespaces exist. Use this when you need deterministic
structure (e.g., for mdoc with multiple namespaces).