Skip to main content

SessionLayer

Struct SessionLayer 

Source
pub struct SessionLayer { /* private fields */ }
Expand description

The session table + session_nb allocator.

Implementations§

Source§

impl SessionLayer

Source

pub fn new() -> Self

New, empty session layer.

Source

pub fn resource_of(&self, session_nb: u16) -> Option<ResourceId>

Resource bound to session_nb, if open.

Source

pub fn session_for(&self, resource: ResourceId) -> Option<u16>

The lowest open session_nb bound to resource, if any.

Walks only the open sessions (a handful per slot), where the caller used to probe every one of the 65 535 representable numbers through resource_of (audit r10-O-9).

Source

pub fn sessions(&self) -> Vec<(u16, ResourceId)>

All open (session_nb, resource) pairs, ascending by session_nb.

Source

pub fn len(&self) -> usize

Number of open sessions.

Source

pub fn is_empty(&self) -> bool

Whether there are no open sessions.

Source

pub fn create_session(&mut self, resource: ResourceId) -> Result<Vec<u8>>

Open a session to a module-provided resource (host-initiated): returns the open_session_request SPDU to send. Sessions are opened the same way in both directions (§8.4.1) — the host sends open_session_request, and the module (the resource provider) assigns the session_nb in its open_session_response. (create_session/0x93 is a resource-manager-internal primitive; a real CAM rejects it with status=0xF0 — verified live against an AlphaCrypt.) The session is recorded once the module’s open_session_response(ok) arrives.

Source

pub fn send_apdu(&self, session_nb: u16, apdu: &[u8]) -> Result<Vec<u8>>

Wrap an APDU for sending on session_nb (session_number + body).

Source

pub fn close(&mut self, session_nb: u16) -> Result<Vec<u8>>

Begin closing session_nb: returns the close_session_request SPDU.

Source

pub fn on_spdu( &mut self, spdu: &[u8], provides: impl Fn(ResourceId) -> bool, ) -> Result<SessionOut>

Handle one inbound SPDU. provides answers “does the host provide this resource?” for an incoming open_session_request.

Trait Implementations§

Source§

impl Debug for SessionLayer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SessionLayer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DescriptorObject for T
where T: Debug + Any + Send + Sync,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrow as &dyn Any so the caller can downcast to the concrete type.
Source§

impl<T> ExtensionObject for T
where T: Debug + Any + Send + Sync,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrow as &dyn Any so the caller can downcast to the concrete type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> TableObject for T
where T: Debug + Any + Send + Sync,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrow as &dyn Any so the caller can downcast to the concrete type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.