pub mod model;
use ic_auth_protocol_types::limits::{MAX_LABEL_BYTES, MAX_SESSION_SCOPES};
pub use ic_wire as wire;
use ic_wire::{Limits, List, Text};
use model::{LogoutResult, PortableCredential};
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "typescript", derive(ic_wire::Wire))]
pub struct SessionInput {
pub credential: PortableCredential,
pub scopes: List<Text<MAX_LABEL_BYTES>, MAX_SESSION_SCOPES>,
pub ttl_secs: Option<u64>,
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "typescript", derive(ic_wire::Wire))]
pub struct SessionView {
pub caller: ic_wire::Bytes<29>,
pub issuer: ic_wire::Bytes<29>,
pub subject: ic_wire::Bytes<29>,
pub expires_at_ns: u64,
}
const CREDENTIAL_LIMITS: Limits = Limits {
bytes: 524288,
allocation: 2097152,
nodes: 65536,
depth: 32,
};
const REPLY_LIMITS: Limits = Limits {
bytes: 4096,
allocation: 16384,
nodes: 128,
depth: 8,
};
const EMPTY_LIMITS: Limits = Limits {
bytes: 11,
allocation: 128,
nodes: 8,
depth: 4,
};
macro_rules! codecs {
($request:ty, $response:ty) => {
pub fn encode_request(value: &$request) -> Result<Vec<u8>, ic_wire::Error> {
ic_wire::native::encode_request(Self::ID, value, Self::REQUEST_LIMITS)
}
pub fn decode_request(bytes: &[u8]) -> Result<$request, ic_wire::Error> {
ic_wire::native::decode_request(Self::ID, bytes, Self::REQUEST_LIMITS)
}
pub fn encode_response(value: &$response) -> Result<Vec<u8>, ic_wire::Error> {
ic_wire::native::encode_response(Self::ID, value, Self::RESPONSE_LIMITS)
}
pub fn decode_response(bytes: &[u8]) -> Result<$response, ic_wire::Error> {
ic_wire::native::decode_response(Self::ID, bytes, Self::RESPONSE_LIMITS)
}
};
}
pub struct CredentialEnvelope;
impl CredentialEnvelope {
pub const ID: u64 = 0x415554480001;
pub const NAME: &'static str = "credential";
pub const REQUEST_LIMITS: Limits = CREDENTIAL_LIMITS;
pub const RESPONSE_LIMITS: Limits = CREDENTIAL_LIMITS;
codecs!(PortableCredential, PortableCredential);
}
pub struct EstablishSession;
impl EstablishSession {
pub const ID: u64 = 0x415554480012;
pub const NAME: &'static str = "establish_portable_session";
pub const REQUEST_LIMITS: Limits = CREDENTIAL_LIMITS;
pub const RESPONSE_LIMITS: Limits = REPLY_LIMITS;
codecs!(SessionInput, Result<SessionView, model::AdmissionRefusal>);
}
pub struct ReadSession;
impl ReadSession {
pub const ID: u64 = 0x415554480003;
pub const NAME: &'static str = "portable_session_read";
pub const REQUEST_LIMITS: Limits = EMPTY_LIMITS;
pub const RESPONSE_LIMITS: Limits = REPLY_LIMITS;
codecs!((), Result<SessionView, Text<256>>);
}
pub struct Logout;
impl Logout {
pub const ID: u64 = 0x415554480004;
pub const NAME: &'static str = "logout_portable_session";
pub const REQUEST_LIMITS: Limits = EMPTY_LIMITS;
pub const RESPONSE_LIMITS: Limits = REPLY_LIMITS;
codecs!((), LogoutResult);
}