KeyRecord

Struct KeyRecord 

Source
pub struct KeyRecord {
Show 14 fields pub id: String, pub hash: String, pub scopes: HashSet<Scope>, pub allowed_markets: Option<HashSet<String>>, pub allowed_symbols: Option<HashSet<String>>, pub max_order_value: Option<f64>, pub max_daily_value: Option<f64>, pub hours_window: Option<String>, pub max_orders_per_minute: Option<u32>, pub allowed_trd_sides: Option<HashSet<String>>, pub expires_at: Option<DateTime<Utc>>, pub created_at: DateTime<Utc>, pub note: Option<String>, pub allowed_machines: Option<Vec<String>>,
}
Expand description

单条 key 的持久化格式

Fields§

§id: String

人读 ID(审计日志用)

§hash: String

“sha256:<64 hex>”

§scopes: HashSet<Scope>§allowed_markets: Option<HashSet<String>>§allowed_symbols: Option<HashSet<String>>§max_order_value: Option<f64>§max_daily_value: Option<f64>§hours_window: Option<String>

“HH:MM-HH:MM” 服务器本地时区;跨午夜用 “22:00-04:00”

§max_orders_per_minute: Option<u32>

每 60s 最多下单次数(滑动窗口,None 表示不限)

§allowed_trd_sides: Option<HashSet<String>>

允许的交易方向,例如 ["SELL"];None 不限

§expires_at: Option<DateTime<Utc>>§created_at: DateTime<Utc>§note: Option<String>§allowed_machines: Option<Vec<String>>

机器绑定指纹列表(软绑定,见 machine 模块)

  • None → 未启用绑定,所有机器可用(向后兼容 v0.7.0 ~ v0.7.x 早期 key)
  • Some(vec![]) → 强制锁定(无机器能通过),可用于临时冻结
  • Some(vec!["<fingerprint_hex>", ...]) → 只允许这些机器

指纹由 machine::fingerprint_for(key_id) 生成,和 key_id 强耦合: 同一台机器上不同 key 的指纹不同。

Implementations§

Source§

impl KeyRecord

Source

pub fn generate( id: impl Into<String>, scopes: HashSet<Scope>, limits: Option<Limits>, expires_at: Option<DateTime<Utc>>, note: Option<String>, ) -> (String, KeyRecord)

生成新 key:返回 (plaintext, record)

plaintext 只会返回给调用方一次,必须立即展示给用户;record 落盘。

Source

pub fn generate_with_machines( id: impl Into<String>, scopes: HashSet<Scope>, limits: Option<Limits>, expires_at: Option<DateTime<Utc>>, note: Option<String>, allowed_machines: Option<Vec<String>>, ) -> (String, KeyRecord)

同 [generate],但允许一次性设置 allowed_machines

Source

pub fn check_machine(&self) -> Result<(), MachineError>

检查本机是否在 allowed_machines 白名单里(None 时始终通过)

Source

pub fn matches(&self, plaintext: &str) -> bool

校验明文与当前记录的 hash 是否一致

Source

pub fn is_expired(&self, now: DateTime<Utc>) -> bool

是否已过期

Source

pub fn hours_range(&self) -> Result<Option<(NaiveTime, NaiveTime)>, String>

解析 hours_window 为 (start, end);None 表示不限

Source

pub fn limits(&self) -> Limits

导出为 Limits

Trait Implementations§

Source§

impl Clone for KeyRecord

Source§

fn clone(&self) -> KeyRecord

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyRecord

Source§

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

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

impl<'de> Deserialize<'de> for KeyRecord

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for KeyRecord

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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.

§

impl<T> Instrument for T

§

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

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

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,