pub mod model;
pub mod projection;
pub use ic_wire as wire;
use ic_wire::{Direction, Encoding, Limits, List, Text};
pub use model::SessionView;
pub const BROWSER_LOGOUT_RESPONSE_BYTES: usize = 1024;
pub const BROWSER_DEFAULT_CREDENTIAL_BYTES: usize = 131_072;
pub const BROWSER_MAX_CONFIGURED_CREDENTIAL_BYTES: usize = 1_048_576;
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "typescript", derive(ic_wire::typescript::Wire))]
#[cfg_attr(feature = "typescript", wire(fixed))]
pub struct SessionInput {
pub credential: model::PortableCredential,
pub scopes: List<Text<64>, 16>,
pub ttl_secs: Option<u64>,
}
const CREDENTIAL_LIMITS: Limits = Limits {
bytes: 524_288,
allocation: 2_097_152,
nodes: 65_536,
depth: 32,
};
const EMPTY_LIMITS: Limits = Limits {
bytes: 11,
allocation: 128,
nodes: 8,
depth: 4,
};
const REPLY_LIMITS: Limits = Limits {
bytes: 4096,
allocation: 16384,
nodes: 128,
depth: 8,
};
const SESSION_REPLY_LIMITS: Limits = Limits {
bytes: 8192,
allocation: 65536,
..REPLY_LIMITS
};
macro_rules! contract {
($contract:ident, $id:expr, $name:literal, $request:ty, $reply:ty, $request_limits:ident, $reply_limits:ident) => {
impl $contract {
pub const ID: u64 = $id;
pub const NAME: &'static str = $name;
pub const REQUEST_LIMITS: Limits = $request_limits;
pub const RESPONSE_LIMITS: Limits = $reply_limits;
pub fn encode_request(value: &$request) -> Result<Vec<u8>, ic_wire::Error> {
ic_wire::encode(
value,
Self::encoding(Direction::Request),
Self::REQUEST_LIMITS,
)
}
pub fn decode_request(bytes: &[u8]) -> Result<$request, ic_wire::Error> {
ic_wire::decode(
bytes,
Self::encoding(Direction::Request),
Self::REQUEST_LIMITS,
)
}
pub fn encode_response(value: &$reply) -> Result<Vec<u8>, ic_wire::Error> {
ic_wire::encode(
value,
Self::encoding(Direction::Response),
Self::RESPONSE_LIMITS,
)
}
pub fn decode_response(bytes: &[u8]) -> Result<$reply, ic_wire::Error> {
ic_wire::decode(
bytes,
Self::encoding(Direction::Response),
Self::RESPONSE_LIMITS,
)
}
const fn encoding(direction: Direction) -> Encoding {
Encoding::Frame {
method: Self::ID,
direction,
}
}
}
};
}
pub struct ReadSession;
contract!(
ReadSession,
0x415554480013,
"portable_session_read",
(),
Result<SessionView, model::SessionReadRefusal>,
EMPTY_LIMITS,
SESSION_REPLY_LIMITS
);
pub struct Logout;
contract!(
Logout,
0x415554480014,
"logout_portable_session",
(),
model::LogoutResult,
EMPTY_LIMITS,
REPLY_LIMITS
);
pub struct CredentialEnvelope;
contract!(
CredentialEnvelope,
0x415554480001,
"credential",
model::PortableCredential,
model::PortableCredential,
CREDENTIAL_LIMITS,
CREDENTIAL_LIMITS
);
pub struct EstablishSession;
contract!(
EstablishSession,
0x415554480012,
"establish_portable_session",
SessionInput,
Result<SessionView, model::AdmissionRefusal>,
CREDENTIAL_LIMITS,
SESSION_REPLY_LIMITS
);