pub struct SessionContext { /* private fields */ }Expand description
Per-partner session context — identity, trust configuration, and correlation
metadata required by every send/receive operation in asx.
§Cardinality and Lifetime
SessionContext is scoped to one trading-partner relationship and
represents a reusable, long-lived object — not a per-message allocation.
Typical lifecycle patterns:
| Deployment style | Recommended granularity |
|---|---|
| Single fixed partner (e.g. one supplier) | One SessionContext per process; share via Arc. |
| Multiple partners (hub/spoke) | One SessionContext per partner; keyed by partner_id. |
| Short-lived CLI / batch | One SessionContext per batch run; Clone is O(1). |
Using a new SessionContext for every outbound message is valid but
wasteful — it pays session-ID generation and cert-validation costs on every
call. Prefer reusing and, when certificates rotate, call
rotate_cert_handle in place rather than rebuilding.
§Observability Impact
The session_id is emitted on every span, metric label, and error context
produced during message processing. Using inconsistent or randomly
generated session_id values per message will fragment observability data
in your monitoring backend and make per-partner dashboards unusable.
Choose a stable, human-readable ID such as "partner-acme-prod".
§Cloning
Clone is O(1) — all heavy data (certificates, trust anchors) is behind
Arc and is not deep-copied. Clones share the same CertHandle lineage
until rotate_cert_handle is called on one of them.
§Construction
Prefer SessionContext::builder for incremental construction, or
SessionContext::new for the minimal three-field shorthand.
Implementations§
Source§impl SessionContext
impl SessionContext
Sourcepub fn builder(
session_id: impl Into<String>,
partner_id: impl Into<String>,
) -> SessionContextBuilder
pub fn builder( session_id: impl Into<String>, partner_id: impl Into<String>, ) -> SessionContextBuilder
Start building a SessionContext incrementally.
pub fn new( session_id: impl Into<String>, partner_id: impl Into<String>, profile_name: impl Into<String>, ) -> Result<Self>
Sourcepub fn with_cert_handle(self, cert_handle: CertHandle) -> Result<Self>
pub fn with_cert_handle(self, cert_handle: CertHandle) -> Result<Self>
Validate and set the session’s certificate/trust configuration (builder method).
This is the primary way to attach certificate material when constructing a
session. For rotation on an already-live session, prefer
rotate_cert_handle which takes &mut self.
Both the trust-anchor parse cache and the X.509 store cache are reset so that the new handle’s anchors are parsed fresh on first use.
Sourcepub fn rotate_cert_handle(&mut self, cert_handle: CertHandle) -> Result<()>
pub fn rotate_cert_handle(&mut self, cert_handle: CertHandle) -> Result<()>
Atomically rotate the certificate/trust configuration on a live session.
Unlike with_cert_handle, this takes &mut self and therefore works
on an already-constructed session without rebuilding it. The session_id,
partner_id, profile, reliability queues, and event subscriptions are
preserved.
Any in-flight verification calls that were already dispatched continue
using the previous Arc<CertHandle> snapshot until they complete; newly
accepted messages see the updated configuration immediately.
§Errors
Returns InvalidInput if cert_handle fails the same validation as
with_cert_handle.
pub fn with_effective_policy_snapshot_json( self, snapshot_json: impl Into<String>, ) -> Result<Self>
pub fn effective_policy_snapshot_json(&self) -> Option<&str>
Sourcepub fn strict_runtime_bootstrap_validated(&self) -> bool
pub fn strict_runtime_bootstrap_validated(&self) -> bool
Return whether this session is explicitly marked as startup-validated for strict-runtime protocol entry point enforcement.
Sourcepub fn test_only_mark_strict_runtime_bootstrap_validated(self) -> Self
pub fn test_only_mark_strict_runtime_bootstrap_validated(self) -> Self
Mark this session as startup-validated without running startup validation.
Test scaffolding only. It is gated behind the testing feature, which
raises a compile_error! in release builds, so it cannot reach a
production binary — the same guarantee that covers
crate::as4::InsecureBypassAs4Verifier.
Production code marks a session by presenting the token that
crate::presets::StrictRuntimeBootstrap mints.
pub fn session_id(&self) -> &str
pub fn partner_id(&self) -> &str
pub fn profile_name(&self) -> &str
pub fn cert_handle(&self) -> &CertHandle
pub fn correlation_scope(&self) -> &CorrelationScope
Sourcepub fn with_incoming_traceparent(self, traceparent: Option<&str>) -> Self
pub fn with_incoming_traceparent(self, traceparent: Option<&str>) -> Self
Attach an inbound W3C Trace Context traceparent header value to this
session so that every ScopedAsxEvent emitted during processing
carries the upstream trace identifier.
Typically called by the embedder’s HTTP handler after parsing the
inbound request with as2_ingress_from_http or
as4_ingress_from_http:
let ingress = as4_ingress_from_http(http_request)?;
let session = SessionContext::new("s1", "partner", "strict")?
.with_incoming_traceparent(ingress.traceparent.as_deref());Passing None is a no-op (leaves any previously set value unchanged
because inbound absence of the header should not clear a manually set
value).
Trait Implementations§
Source§impl Clone for SessionContext
impl Clone for SessionContext
Source§fn clone(&self) -> SessionContext
fn clone(&self) -> SessionContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SessionContext
impl Debug for SessionContext
impl Eq for SessionContext
Source§impl PartialEq for SessionContext
impl PartialEq for SessionContext
impl StructuralPartialEq for SessionContext
Auto Trait Implementations§
impl Freeze for SessionContext
impl RefUnwindSafe for SessionContext
impl Send for SessionContext
impl Sync for SessionContext
impl Unpin for SessionContext
impl UnsafeUnpin for SessionContext
impl UnwindSafe for SessionContext
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more