Skip to main content

SagaHttpMessageAuthenticator

Struct SagaHttpMessageAuthenticator 

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

业务作用:绑定单条 transport 信任边的凭据来源与允许时钟偏差。

同一实例只能代表一个已由部署配置绑定的 producer。签名覆盖 producer、HTTP path、时间戳、 一次性 nonce 和原始 body;接收方校验成功并占用 nonce 后,才能把该 producer 传给 runtime 的 authenticated API。

Implementations§

Source§

impl SagaHttpMessageAuthenticator

Source

pub fn from_hex_key( hex_key: &str, max_clock_skew_ms: u64, ) -> Result<Self, SagaHttpMessageAuthError>

业务作用:从部署注入的 256 位十六进制 key 构造消息认证器。

参数说明:

  • hex_key: 恰好 64 个小写十六进制字符;不得写入日志、代码或 Outbox。
  • max_clock_skew_ms: 接收时间与签名时间允许的最大偏差,必须大于零。

返回:key 与时间窗口合法时返回认证器;否则拒绝启动。

Source

pub fn from_source( source: Arc<dyn SagaHttpCredentialSource>, max_clock_skew_ms: u64, ) -> Result<Self, SagaHttpMessageAuthError>

业务作用:绑定受信凭据快照来源,使既有认证器克隆在下一次请求观察原子轮换。

参数说明:

  • source:只提供已校验材料
  • max_clock_skew_ms:限制签名时钟偏差。

返回:偏差窗口非零时返回认证器;零窗口拒绝装配。

Source

pub fn sign( &self, producer: &ServiceIdentity, path: &str, timestamp_ms: u64, nonce: &str, body: &[u8], ) -> String

业务作用:为一条已持久化 Saga transport payload 生成防篡改身份收据。

参数说明:

  • producer: 此 key 在部署信任表中绑定的逻辑 producer。
  • path: 接收端固定 Saga path,防止签名跨端点复用。
  • timestamp_ms: 发送时 Unix 毫秒。
  • nonce: 每次投递新生成的 128 位小写十六进制随机数。
  • body: 将被原样发送的 HTTP body。

返回:64 字符小写十六进制 HMAC-SHA-256;调用方必须与上述字段一同发送。

Source

pub fn verify( &self, message: &SagaHttpSignedMessage<'_>, now_ms: u64, ) -> Result<(), SagaHttpMessageAuthError>

业务作用:在解析 envelope 前校验 transport producer 收据,但不占用 replay claim。

多副本接收端必须在本方法成功后、进入业务处理前占用共享强一致 nonce;单进程调用方 应使用 SagaHttpReplayGuard::verify_once。只调用本方法不能构成完整的重放防护。

参数说明:

  • message: 冻结 producer/path/timestamp/nonce/body/signature 的原始收据。
  • now_ms: 接收端当前 Unix 毫秒。

返回:身份、路径、时间窗和 body 全部匹配时成功;任一不符返回同一脱敏错误。

Source

pub fn verify_replay_horizon_ms( &self, message: &SagaHttpSignedMessage<'_>, now_ms: u64, ) -> Result<u64, SagaHttpMessageAuthError>

业务作用:校验 transport producer 收据,并给共享 nonce 存储返回由签名时间窗决定的保留边界。

多副本接收端必须把返回值原样用于共享 claim,不能按接收时刻另算较短期限;否则未来偏移 但仍合法的签名会在认证窗口结束前重新取得同一 nonce。

参数说明:

  • message: 冻结 producer/path/timestamp/nonce/body/signature 的原始收据。
  • now_ms: 接收端当前 Unix 毫秒。

返回:身份、路径、时间窗和 body 全部匹配时返回签名合法窗口的闭区间右端;任一不符返回 同一脱敏错误。

Source

pub fn issue_nonce() -> String

业务作用:生成一条 transport 投递专用的不可预测 nonce,供 replay guard 建立一次性门禁。

参数说明: 无。

返回:128 位随机 UUID 的 32 字符小写十六进制表示;调用方不得跨请求复用。

Trait Implementations§

Source§

impl Clone for SagaHttpMessageAuthenticator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more