pub struct SessionLayer { /* private fields */ }Expand description
The session table + session_nb allocator.
Implementations§
Source§impl SessionLayer
impl SessionLayer
Sourcepub fn resource_of(&self, session_nb: u16) -> Option<ResourceId>
pub fn resource_of(&self, session_nb: u16) -> Option<ResourceId>
Resource bound to session_nb, if open.
Sourcepub fn session_for(&self, resource: ResourceId) -> Option<u16>
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).
Sourcepub fn sessions(&self) -> Vec<(u16, ResourceId)>
pub fn sessions(&self) -> Vec<(u16, ResourceId)>
All open (session_nb, resource) pairs, ascending by session_nb.
Sourcepub fn create_session(&mut self, resource: ResourceId) -> Result<Vec<u8>>
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.
Sourcepub fn send_apdu(&self, session_nb: u16, apdu: &[u8]) -> Result<Vec<u8>>
pub fn send_apdu(&self, session_nb: u16, apdu: &[u8]) -> Result<Vec<u8>>
Wrap an APDU for sending on session_nb (session_number + body).
Sourcepub fn close(&mut self, session_nb: u16) -> Result<Vec<u8>>
pub fn close(&mut self, session_nb: u16) -> Result<Vec<u8>>
Begin closing session_nb: returns the close_session_request SPDU.
Sourcepub fn on_spdu(
&mut self,
spdu: &[u8],
provides: impl Fn(ResourceId) -> bool,
) -> Result<SessionOut>
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.