pub struct SecurityContext { /* private fields */ }Expand description
A context for performing security operations.
Implementations§
Source§impl SecurityContext
impl SecurityContext
Sourcepub fn new(key: AuthKey) -> Self
pub fn new(key: AuthKey) -> Self
Creates a new security context with the given key and default settings.
Sourcepub fn for_testing(seed: u64) -> Self
pub fn for_testing(seed: u64) -> Self
Creates a security context for testing with a deterministic seed.
Sourcepub fn from_config(key: AuthKey, mode: AuthMode) -> Self
pub fn from_config(key: AuthKey, mode: AuthMode) -> Self
br-asupersync-x7ad3b: constructs a context at a deployment-configured
AuthMode, selected at CONSTRUCTION time.
This is the sanctioned production path for building a non-Strict
context: Self::with_mode deliberately panics on downgrades because a
runtime transition to a looser mode is almost always a bug, but a
deployment that declares auth_mode in its crate::config::SecurityConfig
is making an explicit, audited mode choice up front (see the module doc
on with_mode). crate::config::SecurityConfig::build_context is the
only intended caller; it threads the operator’s configured mode and key
seed into the live decode path so the RAPTORQ_SECURITY_AUTH_MODE /
RAPTORQ_SECURITY_AUTH_KEY_SEED knobs actually take effect instead of
being parsed-and-ignored phantom controls.
Sourcepub fn with_mode(self, mode: AuthMode) -> Self
pub fn with_mode(self, mode: AuthMode) -> Self
Sets the authentication mode.
§br-asupersync-jgpcvp: NO-DOWNGRADE policy
with_mode only allows transitions to a mode that is at
least as strict as the current mode. Strictness order is
Strict > Permissive > Disabled, so the allowed transitions
are:
- Strict → Strict (no-op)
- Permissive → Strict / Permissive
- Disabled → Strict / Permissive / Disabled
Downgrades (Strict → Permissive, Strict → Disabled, Permissive → Disabled) are REJECTED by panicking with a security-sensitive message. Pre-fix, any caller could flip a strict context to Permissive at any time, silently bypassing authentication for every subsequent symbol verification.
Tests that need to verify Permissive / Disabled behavior must
construct via [Self::for_testing_with_mode] instead.
§Panics
Panics if mode is less strict than the current mode. The
panic message identifies the attempted downgrade for diagnosis.
This is a security-sensitive operation; silent-ignore would
leave the caller believing the downgrade succeeded.
Sourcepub fn sign_symbol(&self, symbol: &Symbol) -> AuthenticatedSymbol
pub fn sign_symbol(&self, symbol: &Symbol) -> AuthenticatedSymbol
Signs a symbol, producing an authenticated symbol.
Sourcepub fn sign_symbol_tag(&self, symbol: &Symbol) -> AuthenticationTag
pub fn sign_symbol_tag(&self, symbol: &Symbol) -> AuthenticationTag
Computes the authentication tag for a symbol without cloning the symbol.
Hot transport paths use this when they only need to append the tag bytes to an existing wire envelope.
Sourcepub fn verify_authenticated_symbol(
&self,
auth: &mut AuthenticatedSymbol,
) -> Result<(), AuthError>
pub fn verify_authenticated_symbol( &self, auth: &mut AuthenticatedSymbol, ) -> Result<(), AuthError>
Verifies an authenticated symbol.
The behavior depends on the configured AuthMode:
Strict: ReturnsErron failure.Permissive: ReturnsOkon failure (butverifiedflag remains false).Disabled: ReturnsOkwithout checking and leaves the currentverifiedflag intact.
If verification runs, the verified flag is updated to match the current result.
Sourcepub fn derive_context(&self, purpose: &[u8]) -> Self
pub fn derive_context(&self, purpose: &[u8]) -> Self
Derives a child context with a subkey.
Authorizes a replica in this context’s signed membership registry.
§Errors
Returns AuthErrorKind::MalformedPayload when the replica or region
identifier is not a stable wire-safe identifier.
Imports an externally-stored signed replica authorization receipt.
§Errors
Returns AuthErrorKind::InvalidTag if the record signature does not
verify against this context’s key.
Revokes a replica authorization from the in-memory registry.
Validates whether a replica is authorized to participate in symbol assignment.
asupersync-j18rga: Checks replica credentials against the security context. This prevents unauthorized replicas from joining symbol distribution.
§Arguments
replica_id- The replica identifier to validateregion_id- Optional region context for scoped authorization
§Returns
true if the replica is authorized, false otherwise.
Trait Implementations§
Source§impl Clone for SecurityContext
impl Clone for SecurityContext
Source§fn clone(&self) -> SecurityContext
fn clone(&self) -> SecurityContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more