dpp_vc/credential/revocation.rs
1use crate::status_list::StatusList;
2
3use super::types::DppAccessCredential;
4
5/// Outcome of resolving a credential's revocation status against a status list.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum RevocationOutcome {
8 /// The status bit is clear — the credential is not revoked.
9 NotRevoked,
10 /// The status bit is set — the credential is revoked.
11 Revoked,
12 /// The credential declares a status that the provided list cannot answer
13 /// (no/invalid index, index out of range). Callers MUST fail closed.
14 Indeterminate,
15}
16
17/// Resolve a credential's revocation status against an **already-fetched** status
18/// list. Fetching the status-list credential over the network is an
19/// infrastructure concern handled by the platform (crypto Gap 5) — this is the
20/// pure decision given the list.
21///
22/// A credential that declares no `credentialStatus` is `NotRevoked` (there is
23/// nothing to revoke against).
24pub fn check_revocation(
25 credential: &DppAccessCredential,
26 status_list: &StatusList,
27) -> RevocationOutcome {
28 let Some(status) = credential.credential_status.as_ref() else {
29 return RevocationOutcome::NotRevoked;
30 };
31 let Some(index) = status
32 .status_list_index
33 .as_ref()
34 .and_then(|s| s.parse::<usize>().ok())
35 else {
36 return RevocationOutcome::Indeterminate;
37 };
38 match status_list.get(index) {
39 Some(true) => RevocationOutcome::Revoked,
40 Some(false) => RevocationOutcome::NotRevoked,
41 None => RevocationOutcome::Indeterminate,
42 }
43}