Skip to main content

ic_auth_wire/model/
mod.rs

1//! Transport records and discriminants, kept distinct from engine decisions.
2
3mod credential;
4
5use ic_auth_protocol_types::Principal;
6use serde::{Deserialize, Serialize};
7
8pub use credential::{
9    AudienceId, CertifiedProof, ChainKeyAlgorithm, ChainKeyBatchHeaderV1,
10    ChainKeyBatchWitnessStepV1, ChainKeyBatchWitnessV1, ChainKeyDelegationCertV1, ChainKeyKeyId,
11    ChainKeyRootSignatureV1, DelegatedRoleGrant, DelegationAudience, DelegationCert,
12    DelegationProof, IcCanisterSignatureProofV1, IcChainKeyBatchSignatureProofV1,
13    IssuerProofAlgorithm, IssuerProofBinding, PortableCredential, PortableProof, RootProof,
14};
15
16///
17/// AdmissionRefusal
18///
19/// Session-admission refusals in their fixed transport order.
20///
21
22#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
23#[cfg_attr(feature = "typescript", derive(ic_wire::typescript::Wire))]
24pub enum AdmissionRefusal {
25    /// Credential is not yet valid at trusted time.
26    NotYetValid,
27    /// Credential has expired for fresh admission.
28    Expired,
29    /// Credential verification failed.
30    InvalidCredential,
31    /// Protected authority is not ready.
32    AuthorityUnavailable,
33    /// Credential predates the protected reset boundary.
34    BeforeReset,
35    /// Requested scopes are not admitted.
36    ScopeRejected,
37    /// A consumed credential conflicts with this request.
38    ReplayConflict,
39    /// Retained revocation prevents admission.
40    Revoked,
41    /// Required bounded state has no capacity.
42    Capacity,
43    /// The applicable attempt budget is exhausted.
44    Throttled,
45    /// Admission could not be completed.
46    Unavailable,
47}
48
49///
50/// SessionView
51///
52/// A local session receipt; receiving or constructing it grants no authority.
53///
54
55#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
56#[cfg_attr(feature = "typescript", derive(ic_wire::typescript::Wire))]
57#[cfg_attr(feature = "typescript", wire(fixed))]
58pub struct SessionView {
59    /// Host-authenticated browser principal bound to the session.
60    pub caller: Principal,
61    /// Issuer qualifying the subject.
62    pub issuer: Principal,
63    /// Issuer-qualified account subject.
64    pub subject: Principal,
65    /// Exclusive local lease deadline in nanoseconds.
66    pub expires_at_ns: u64,
67    /// Opaque issuer-attested application bytes, up to 4096 bytes.
68    pub ext: Option<ic_wire::Bytes<{ ic_auth_protocol_types::MAX_TOKEN_EXT_BYTES }>>,
69}
70
71///
72/// SessionReadRefusal
73///
74/// Existing read-refusal discriminants, in their fixed Wire order.
75///
76
77#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
78#[cfg_attr(feature = "typescript", derive(ic_wire::typescript::Wire))]
79pub enum SessionReadRefusal {
80    /// No live local session.
81    MissingOrExpired,
82    /// Protected authority is not ready.
83    AuthorityUnavailable,
84    /// The required scope is not granted.
85    ScopeRejected,
86    /// Revocation prevents use.
87    Revoked,
88    /// The read could not be completed.
89    Unavailable,
90}
91
92///
93/// LogoutUnavailable
94///
95/// Existing unavailable-logout discriminants, in their fixed Wire order.
96///
97
98#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
99#[cfg_attr(feature = "typescript", derive(ic_wire::typescript::Wire))]
100pub enum LogoutUnavailable {
101    /// No capacity to retain the required denial.
102    Capacity,
103    /// Storage could not commit the denial.
104    Storage,
105    /// Trusted time could not support the operation.
106    Clock,
107    /// A reset is pending.
108    ResetPending,
109}
110
111///
112/// LogoutResult
113///
114/// Local logout result; no variant acknowledges logout at another receiver.
115///
116
117#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
118#[cfg_attr(feature = "typescript", derive(ic_wire::typescript::Wire))]
119pub enum LogoutResult {
120    /// Committed denial through this nanosecond deadline.
121    Revoked(u64),
122    /// Local denial deadline without confirmation of outstanding issuance.
123    Unconfirmed(u64),
124    /// The host-authenticated caller is not a valid logout identity.
125    InvalidCaller,
126    /// No revocation acknowledgement; issuance uncertainty must be retained.
127    Unavailable(LogoutUnavailable),
128}