security

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package security 提供 XOps v2 纯函数数学安全内核。

本包恪守 100% 纯数学与零副作用铁律(零 sync/sync/atomic/context/os/net/reflect/crypto/rand/time.Now):

  • 有界安全格:Verdict 交半格、RiskLevel 并半格(零值 RiskUnknown 失败关闭)、 GuardrailDecision 封闭和类型及 NodeOverrides 顺序无关格折叠;
  • 幻影能力封闭类型集:Capability(CapInspect..CapMutate)及序列化枚举 CapabilityKind;
  • 操作与链路身份、规范绑定与审批信封:TraceID、OperationID、SHA-256 Digest、经 digestcover 静态校验的 OperationBinding 与 ApprovalEnvelope,以及双阶段路径规范化升级判定 CanonicalScopeEscalated。

架构隔离铁律(ADR-008):运行期能力证明 Authorized[C] 物理独占定义于 core/internal/gate,严禁在本包定义。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVerdict          = errors.New("security: 无效的 Verdict")
	ErrInvalidRiskLevel        = errors.New("security: 无效的 RiskLevel")
	ErrInvalidDecision         = errors.New("security: 无效的 GuardrailDecision")
	ErrInvalidCapability       = errors.New("security: 无效的 Capability")
	ErrInvalidGlob             = errors.New("security: 无效的通配符模式")
	ErrInvalidNodeOverride     = errors.New("security: 无效的 NodeOverrides 规则")
	ErrInvalidTraceID          = errors.New("security: 无效的 TraceID")
	ErrInvalidOperationID      = errors.New("security: 无效的 OperationID")
	ErrNilEntropy              = errors.New("security: 熵源 io.Reader 不能为 nil")
	ErrInvalidDigest           = errors.New("security: 无效的 SHA-256 Digest")
	ErrInvalidOperationBinding = errors.New("security: 无效的 OperationBinding")
	ErrInvalidApprovalEnvelope = errors.New("security: 无效的 ApprovalEnvelope")
	ErrInvalidScopeSnapshot    = errors.New("security: 无效的 ScopeSnapshot")
	ErrNilWriter               = errors.New("security: WriteCanonical 目标 writer 不能为 nil")
	ErrNilReceiver             = errors.New("security: 反序列化目标接收者不能为 nil")
)

本包导出的规范化哨兵错误集合,均由失败关闭路径显式返回以便调用方使用 errors.Is 判定。

Functions

func CanonicalScopeEscalated

func CanonicalScopeEscalated(lexical, canonical ScopeSnapshot) bool

CanonicalScopeEscalated 纯数学判定词法预检快照 lexical 与规范化解析快照 canonical 之间 是否发生安全作用域升级、受保护分区重定向(含同风险同决策的 Protected-A -> Protected-B)或目标漂移(INV-E5)。 遵循严格失败关闭原则:任一快照无效或为零值时恒返回 true。

func EqualDecision

func EqualDecision(a, b GuardrailDecision) bool

EqualDecision 按值严格比较两个 GuardrailDecision 是否均有效且完全一致(nil 或无效零值恒返回 false)。

func MarshalDecisionTo

func MarshalDecisionTo(enc *jsontext.Encoder, d GuardrailDecision) error

MarshalDecisionTo 将任意有效 GuardrailDecision 编码至 Go 1.27 JSON/v2 流; 对 nil、typed-nil 或未初始化零值变体一律失败关闭返回 ErrInvalidDecision。

func MatchGlob

func MatchGlob(pattern, target string) (bool, error)

MatchGlob 使用操作系统无关的 O(|P|*|S|) UTF-8 码点引擎执行通配符匹配(INV-E3): '*' 跨 '/'、'\' 与换行匹配任意序列,'?' 匹配单码点,'[...]' 支持取反与范围,'\' 恒为字面字符。

func NewApprovalNonceFrom

func NewApprovalNonceFrom(entropy io.Reader) ([approvalNonceBytes]byte, error)

NewApprovalNonceFrom 从显式注入熵源读取 16 字节非全零审批防重放 Nonce(零隐式 crypto/rand)。

func SanitizePromptText

func SanitizePromptText(raw string) string

SanitizePromptText 将 C0/DEL/C1 控制字符、Unicode 行/段分隔符(U+2028/U+2029)、 Unicode Cf 格式字符(含 Bidi 覆写/隔离与零宽字符)转义为可打印 ASCII 序列, 并将非法 UTF-8 原始字节显式转义为 \xHH,抵御审批提示伪造与 Trojan-Source 视觉欺骗。

func ValidateGlob

func ValidateGlob(pattern string) error

ValidateGlob 校验操作系统无关的护栏 UTF-8 通配符模式语法, 拒绝空串、非法 UTF-8、控制字符、Unicode Cf(含 Bidi 双向控制与零宽字符)以及畸形字符类。

Types

type ApprovalEnvelope

type ApprovalEnvelope struct {
	// contains filtered or unexported fields
}

ApprovalEnvelope 是密码学锚定操作标识、规范绑定、风险等级、护栏决策、作用域摘要、签发时刻、 有效期与防重放 Nonce 的不可变审批挑战信封(INV-E5 / RFC §3.5–3.6); 零值恒无效,且经 //xops:canonicalhash 由 xopsvet/digestcover 校验 WriteCanonical 全字段覆盖(零 reflect)。

func NewApprovalEnvelope

func NewApprovalEnvelope(spec ApprovalEnvelopeSpec) (ApprovalEnvelope, error)

NewApprovalEnvelope 校验全部安全字段、RFC 3339 时间窗口与决策风险一致性并构造不可变 ApprovalEnvelope。

func (ApprovalEnvelope) Binding

func (e ApprovalEnvelope) Binding() OperationBinding

Binding 返回信封绑定的不可变操作绑定快照。

func (ApprovalEnvelope) CanApprove

func (e ApprovalEnvelope) CanApprove() bool

CanApprove 报告该信封是否代表可进入用户确认流程的待审批挑战(仅 DecisionNeedApproval 返回 true)。

func (ApprovalEnvelope) CanonicalJSON

func (e ApprovalEnvelope) CanonicalJSON() ([]byte, error)

CanonicalJSON 使用 Go 1.27 encoding/json/v2 的 Deterministic(true) 编码确定性 JSON 字节流。

func (ApprovalEnvelope) Decision

func (e ApprovalEnvelope) Decision() GuardrailDecision

Decision 返回信封锁定的护栏决策副本;无效零值失败关闭返回 *DecisionDeny。

func (ApprovalEnvelope) Digest

func (e ApprovalEnvelope) Digest() (Digest, error)

Digest 计算并返回 ApprovalEnvelope 的确定性 SHA-256 规范摘要。

func (ApprovalEnvelope) Equal

func (e ApprovalEnvelope) Equal(other ApprovalEnvelope) bool

Equal 严格比对两个 ApprovalEnvelope 是否均有效且全部字段一致(Nonce 采用常量时间比对)。

func (ApprovalEnvelope) ExpiresAt

func (e ApprovalEnvelope) ExpiresAt() (time.Time, bool)

ExpiresAt 返回信封到期 UTC 时刻(issuedAt + ttl)与有效性标志。

func (ApprovalEnvelope) IsActiveAt

func (e ApprovalEnvelope) IsActiveAt(now time.Time) bool

IsActiveAt 报告信封在显式观测时刻 now 是否处于有效窗口 [issuedAt, issuedAt+ttl) 内。

func (ApprovalEnvelope) IsExpiredAt

func (e ApprovalEnvelope) IsExpiredAt(now time.Time) bool

IsExpiredAt 在显式观测时刻 now 判断信封是否已过期(零 time.Now);无效或零时刻失败关闭返回 true。

func (ApprovalEnvelope) IsValid

func (e ApprovalEnvelope) IsValid() bool

IsValid 报告审批信封是否经构造器完整校验且所有不变量成立。

func (ApprovalEnvelope) IsZero

func (e ApprovalEnvelope) IsZero() bool

IsZero 报告审批信封是否为无效零值。

func (ApprovalEnvelope) IssuedAt

func (e ApprovalEnvelope) IssuedAt() time.Time

IssuedAt 返回规范化的 UTC 签发时刻。

func (ApprovalEnvelope) MarshalJSONTo

func (e ApprovalEnvelope) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值信封失败关闭。

func (ApprovalEnvelope) MatchesBinding

func (e ApprovalEnvelope) MatchesBinding(binding OperationBinding) bool

MatchesBinding 校验给定 OperationBinding 是否与信封锁定绑定完全一致(无效零值恒返回 false)。

func (ApprovalEnvelope) MatchesDigest

func (e ApprovalEnvelope) MatchesDigest(expected Digest) (bool, error)

MatchesDigest 计算本信封的规范 SHA-256 摘要并以常量时间与 expected 比对。

func (ApprovalEnvelope) Nonce

func (e ApprovalEnvelope) Nonce() ([approvalNonceBytes]byte, bool)

Nonce 返回 16 字节防重放 Nonce 副本与有效性标志。

func (ApprovalEnvelope) NonceHex

func (e ApprovalEnvelope) NonceHex() string

NonceHex 返回 32 位小写十六进制防重放 Nonce;无效零值返回空串。

func (ApprovalEnvelope) OperationID

func (e ApprovalEnvelope) OperationID() OperationID

OperationID 返回信封绑定的操作唯一标识。

func (ApprovalEnvelope) PolicyDigest

func (e ApprovalEnvelope) PolicyDigest() algebraic.Option[Digest]

PolicyDigest 返回可选活跃策略快照摘要。

func (ApprovalEnvelope) Risk

func (e ApprovalEnvelope) Risk() RiskLevel

Risk 返回信封锁定的操作风险等级;无效零值返回 RiskUnknown。

func (ApprovalEnvelope) ScopeSummary

func (e ApprovalEnvelope) ScopeSummary() string

ScopeSummary 返回已脱敏的审批范围摘要文本。

func (ApprovalEnvelope) TTL

TTL 返回信封有效期(algebraic.Duration)。

func (*ApprovalEnvelope) UnmarshalJSONFrom

func (e *ApprovalEnvelope) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或篡改值失败关闭并重置零值。

func (ApprovalEnvelope) WriteCanonical

func (e ApprovalEnvelope) WriteCanonical(w io.Writer) error

WriteCanonical 以零反射、长度前缀与域分离方式将 ApprovalEnvelope 全部字段写入 w(受 digestcover 校验)。

type ApprovalEnvelopeSpec

type ApprovalEnvelopeSpec struct {
	OperationID  OperationID
	Binding      OperationBinding
	Risk         RiskLevel
	Decision     GuardrailDecision
	ScopeSummary string
	IssuedAt     time.Time
	TTL          algebraic.Duration
	Nonce        [approvalNonceBytes]byte
	PolicyDigest algebraic.Option[Digest]
}

ApprovalEnvelopeSpec 是构造不可变 ApprovalEnvelope 的显式入参规格; IssuedAt 与 IssuedAt+TTL 均须落在 RFC 3339 合法年份 [1, 9999] 且无溢出,TTL 统一使用 algebraic.Duration, Nonce 须非全零 16 字节,且当 Decision 为 *DecisionNeedApproval 时 spec.Risk 必须与审批决策风险严格一致。

type CapExecute

type CapExecute struct {
	// contains filtered or unexported fields
}

CapExecute 表示远端命令执行或交互式 Shell/PTY 会话能力。

func (CapExecute) Kind

func (CapExecute) Kind() CapabilityKind

Kind 返回 CapExecute 对应的运行期能力类别。

type CapFileMut

type CapFileMut struct {
	// contains filtered or unexported fields
}

CapFileMut 表示远端文件写入、补丁修改或目录结构变更能力。

func (CapFileMut) Kind

func (CapFileMut) Kind() CapabilityKind

Kind 返回 CapFileMut 对应的运行期能力类别。

type CapFileRead

type CapFileRead struct {
	// contains filtered or unexported fields
}

CapFileRead 表示远端文件读取或元信息查询能力。

func (CapFileRead) Kind

func (CapFileRead) Kind() CapabilityKind

Kind 返回 CapFileRead 对应的运行期能力类别。

type CapInspect

type CapInspect struct {
	// contains filtered or unexported fields
}

CapInspect 表示只读探测、节点/会话列举或状态查询能力。

func (CapInspect) Kind

func (CapInspect) Kind() CapabilityKind

Kind 返回 CapInspect 对应的运行期能力类别。

type CapMutate

type CapMutate struct {
	// contains filtered or unexported fields
}

CapMutate 表示本机配置、凭据 Vault 或已知主机信任库变更能力。

func (CapMutate) Kind

func (CapMutate) Kind() CapabilityKind

Kind 返回 CapMutate 对应的运行期能力类别。

type CapTransfer

type CapTransfer struct {
	// contains filtered or unexported fields
}

CapTransfer 表示跨主机文件传输(SCP、SFTP、MCP HTTP 分片流)能力。

func (CapTransfer) Kind

func (CapTransfer) Kind() CapabilityKind

Kind 返回 CapTransfer 对应的运行期能力类别。

type CapTunnel

type CapTunnel struct {
	// contains filtered or unexported fields
}

CapTunnel 表示 SSH 端口转发(-L/-R/-D/StreamLocal/TUN)能力。

func (CapTunnel) Kind

func (CapTunnel) Kind() CapabilityKind

Kind 返回 CapTunnel 对应的运行期能力类别。

type Capability

type Capability interface {
	// contains filtered or unexported methods
}

Capability 是 XOps v2 编译期幻影能力封闭类型集(RFC §3.1),仅用于 core/internal/gate.Authorized[C] 等泛型能力证明的类型约束,100% 纯数学且零同步原语。

type CapabilityKind

type CapabilityKind uint8

CapabilityKind 是幻影类型集 Capability 对应的可序列化能力枚举;零值恒为 CapabilityInvalid。

const (
	CapabilityInvalid  CapabilityKind = iota // 零值无效能力(失败关闭默认值)
	CapabilityInspect                        // 对应幻影类型 CapInspect
	CapabilityExecute                        // 对应幻影类型 CapExecute
	CapabilityFileRead                       // 对应幻影类型 CapFileRead
	CapabilityFileMut                        // 对应幻影类型 CapFileMut
	CapabilityTransfer                       // 对应幻影类型 CapTransfer
	CapabilityTunnel                         // 对应幻影类型 CapTunnel
	CapabilityMutate                         // 对应幻影类型 CapMutate
)

func CapabilityKindOf

func CapabilityKindOf[C Capability]() CapabilityKind

CapabilityKindOf 在编译期类型参数 C 与运行期 CapabilityKind 间建立穷尽映射;接口零值 nil 返回 CapabilityInvalid。

func ParseCapabilityKind

func ParseCapabilityKind(raw string) (CapabilityKind, error)

ParseCapabilityKind 严格解析规范小写能力类别文本。

func (CapabilityKind) AppendText

func (k CapabilityKind) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对无效值严格失败关闭。

func (CapabilityKind) Compare

func (k CapabilityKind) Compare(other CapabilityKind) int

Compare 定义 CapabilityKind 上的确定性全序(无效值排在最前)。

func (CapabilityKind) IsValid

func (k CapabilityKind) IsValid() bool

IsValid 报告 k 是否为 7 种合法能力类别之一。

func (CapabilityKind) IsZero

func (k CapabilityKind) IsZero() bool

IsZero 报告 k 是否处于零值无效态。

func (CapabilityKind) MarshalText

func (k CapabilityKind) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (CapabilityKind) String

func (k CapabilityKind) String() string

String 返回能力类别的规范小写文本;无效值返回 "invalid"。

func (*CapabilityKind) UnmarshalText

func (k *CapabilityKind) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 CapabilityInvalid 并失败关闭。

type DecisionAllow

type DecisionAllow struct {
	// contains filtered or unexported fields
}

DecisionAllow 表示策略在当前上下文下显式允许执行; 内置正向门控 valid bool,未初始化零值与 typed-nil 均失败关闭为拒绝。

func NewDecisionAllow

func NewDecisionAllow(reason string) *DecisionAllow

NewDecisionAllow 构造经显式策略核准的不可变放行决策。

func (*DecisionAllow) IsValid

func (d *DecisionAllow) IsValid() bool

IsValid 报告放行决策是否非 nil 且经合法构造器签发。

func (*DecisionAllow) Kind

func (d *DecisionAllow) Kind() DecisionKind

Kind 有效时返回 DecisionKindAllow;无效时失败关闭返回 DecisionKindDeny。

func (DecisionAllow) MarshalJSONTo

func (d DecisionAllow) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值/无效实例失败关闭。

func (*DecisionAllow) Reason

func (d *DecisionAllow) Reason() string

Reason 返回脱敏放行说明;无效时返回空串。

func (*DecisionAllow) ToVerdict

func (d *DecisionAllow) ToVerdict() Verdict

ToVerdict 有效时返回 VerdictAllow;无效时失败关闭返回 VerdictDeny。

type DecisionDeny

type DecisionDeny struct {
	// contains filtered or unexported fields
}

DecisionDeny 表示无条件拒绝执行该操作(限制支配格吸收顶元;零值语义仍为拒绝)。

func NewDecisionDeny

func NewDecisionDeny(reason string) *DecisionDeny

NewDecisionDeny 构造携带脱敏原因文本的不可变拒绝决策。

func NewDecisionDenyWithCode

func NewDecisionDenyWithCode(code, reason string) *DecisionDeny

NewDecisionDenyWithCode 构造携带机器可读拒绝码与原因文本的不可变拒绝决策。

func (*DecisionDeny) Code

func (d *DecisionDeny) Code() string

Code 返回拒绝原因代码;nil 接收者返回空串。

func (*DecisionDeny) IsValid

func (d *DecisionDeny) IsValid() bool

IsValid 报告拒绝决策实例是否非 nil。

func (*DecisionDeny) Kind

func (*DecisionDeny) Kind() DecisionKind

Kind 恒返回 DecisionKindDeny。

func (DecisionDeny) MarshalJSONTo

func (d DecisionDeny) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者),输出规范拒绝变体对象。

func (*DecisionDeny) Reason

func (d *DecisionDeny) Reason() string

Reason 返回脱敏拒绝原因;nil 接收者返回空串。

func (*DecisionDeny) ToVerdict

func (*DecisionDeny) ToVerdict() Verdict

ToVerdict 恒返回 VerdictDeny。

type DecisionKind

type DecisionKind uint8

DecisionKind 表示 GuardrailDecision 的三态判别枚举,零值恒为 DecisionKindDeny(限制支配吸收元)。

const (
	DecisionKindDeny         DecisionKind = iota // 零值失败关闭判定类别(最严,吸收 NeedApproval 与 Allow)
	DecisionKindNeedApproval                     // 需用户显式审批挑战(次严,吸收 Allow)
	DecisionKindAllow                            // 策略显式允许执行(最宽,限制支配并半格单位元)
)

func ParseDecisionKind

func ParseDecisionKind(raw string) (DecisionKind, error)

ParseDecisionKind 严格解析规范小写决策类别("deny"、"need_approval"、"allow")。

func (DecisionKind) AppendText

func (k DecisionKind) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对非法越界值失败关闭。

func (DecisionKind) CompareStrictness

func (k DecisionKind) CompareStrictness(other DecisionKind) int

CompareStrictness 按限制严苛度顺序比较两个 DecisionKind。

func (DecisionKind) IsValid

func (k DecisionKind) IsValid() bool

IsValid 报告 k 是否为合法的 DecisionKind。

func (DecisionKind) IsZero

func (k DecisionKind) IsZero() bool

IsZero 报告 k 是否处于零值拒绝态(DecisionKindDeny)。

func (DecisionKind) Join

func (k DecisionKind) Join(other DecisionKind) DecisionKind

Join 按限制支配规则合并两个 DecisionKind(Deny 吸收 NeedApproval 吸收 Allow;非法值折叠为 Deny)。

func (DecisionKind) MarshalText

func (k DecisionKind) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (DecisionKind) StrictnessRank

func (k DecisionKind) StrictnessRank() uint8

StrictnessRank 返回决策限制严苛度全序秩(Allow=1 < NeedApproval=2 < Deny/非法=3)。

func (DecisionKind) String

func (k DecisionKind) String() string

String 返回规范小写文本;非法值返回 "deny(invalid)"。

func (DecisionKind) ToVerdict

func (k DecisionKind) ToVerdict() Verdict

ToVerdict 将 DecisionKind 投影到二值 Verdict:仅显式 DecisionKindAllow 映射为 VerdictAllow。

func (*DecisionKind) UnmarshalText

func (k *DecisionKind) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 DecisionKindDeny 并失败关闭。

type DecisionNeedApproval

type DecisionNeedApproval struct {
	// contains filtered or unexported fields
}

DecisionNeedApproval 表示操作必须经用户显式审批挑战方可放行; 内置正向门控 valid bool,未初始化零值与 typed-nil 均失败关闭为 DecisionDeny。

func NewDecisionNeedApproval

func NewDecisionNeedApproval(risk RiskLevel, reason string) (*DecisionNeedApproval, error)

NewDecisionNeedApproval 校验风险等级并构造不可变需审批决策。

func (*DecisionNeedApproval) IsValid

func (d *DecisionNeedApproval) IsValid() bool

IsValid 报告审批决策是否有效且携带合法风险等级。

func (*DecisionNeedApproval) Kind

Kind 有效时返回 DecisionKindNeedApproval,无效时失败关闭返回 DecisionKindDeny。

func (DecisionNeedApproval) MarshalJSONTo

func (d DecisionNeedApproval) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值/无效实例失败关闭。

func (*DecisionNeedApproval) Reason

func (d *DecisionNeedApproval) Reason() string

Reason 返回脱敏审批提示原因;无效时返回空串。

func (*DecisionNeedApproval) Risk

func (d *DecisionNeedApproval) Risk() RiskLevel

Risk 返回触发审批的风险等级;无效时返回 RiskUnknown。

func (*DecisionNeedApproval) ToVerdict

func (*DecisionNeedApproval) ToVerdict() Verdict

ToVerdict 恒返回 VerdictDeny(获批前严禁放行)。

type Digest

type Digest struct {
	// contains filtered or unexported fields
}

Digest 表示规范化的不可变 SHA-256 密码学摘要值对象("sha256:<64位小写十六进制>"); 零值恒无效,Equal 使用 crypto/subtle.ConstantTimeCompare 抵御时序侧信道。

func DigestBytes

func DigestBytes(data []byte) Digest

DigestBytes 对字节切片计算 SHA-256 并返回不可变 Digest。

func DigestFromSHA256

func DigestFromSHA256(sum [sha256.Size]byte) Digest

DigestFromSHA256 将 32 字节 SHA-256 摘要封装为不可变 Digest。

func ParseDigest

func ParseDigest(raw string) (Digest, error)

ParseDigest 严格解析规范 SHA-256 摘要文本("sha256:<64位小写十六进制>")。

func (Digest) AppendText

func (d Digest) AppendText(b []byte) ([]byte, error)

AppendText、MarshalText 与 UnmarshalText 实现 Digest 的值接收者文本编解码(零值与非法输入失败关闭)。

func (Digest) Bytes

func (d Digest) Bytes() ([sha256.Size]byte, bool)

func (Digest) Compare

func (d Digest) Compare(other Digest) int

func (Digest) Equal

func (d Digest) Equal(other Digest) bool

func (Digest) Hex

func (d Digest) Hex() string

func (Digest) IsValid

func (d Digest) IsValid() bool

IsValid、IsZero、Bytes、Hex、String、Equal 与 Compare 实现 Digest 的失败关闭语义、常量时间比对与确定性全序。

func (Digest) IsZero

func (d Digest) IsZero() bool

func (Digest) MarshalText

func (d Digest) MarshalText() ([]byte, error)

func (Digest) String

func (d Digest) String() string

func (*Digest) UnmarshalText

func (d *Digest) UnmarshalText(text []byte) error

type EscalationReason

type EscalationReason uint8

EscalationReason 表示 CanonicalScopeEscalated 触发重提示或拒绝的结构化升级原因枚举;零值恒为 EscalationUnknown。

const (
	EscalationUnknown               EscalationReason = iota // 未知或未分类升级原因(零值失败关闭)
	EscalationInvalidInput                                  // 词法或规范快照之一为零值/无效,失败关闭判定升级
	EscalationCapabilityDrift                               // 操作能力类别发生跨界漂移
	EscalationTargetNodeDrift                               // 目标节点身份发生漂移
	EscalationEndpointDrift                                 // 目标 SSH 端点(主机或端口)发生漂移
	EscalationVerdictTightened                              // 二值安全判定由 Allow 收紧为 Deny
	EscalationRiskIncreased                                 // 操作风险等级升高
	EscalationDecisionTightened                             // 护栏决策收紧
	EscalationDecisionRiskIncreased                         // 同为 NeedApproval 决策但内部审批风险等级升高
	EscalationProtectedTransition                           // 路径由非受保护区进入受保护区
	EscalationProtectedRedirect                             // 受保护路径发生软链重定向或新增受保护分区(含 Protected-A -> Protected-B)
	EscalationRecursiveExpanded                             // 同路径由非递归翻转为递归,或未匹配规范递归根数量净增
	EscalationPathPresenceDrift                             // 路径集合在空集与非空集之间发生结构性漂移
)

func ParseEscalationReason

func ParseEscalationReason(raw string) (EscalationReason, error)

ParseEscalationReason 解析规范小写升级原因标识。

func (EscalationReason) AppendText

func (r EscalationReason) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对零值 EscalationUnknown 失败关闭。

func (EscalationReason) IsValid

func (r EscalationReason) IsValid() bool

IsValid 报告 r 是否为明确的已定义升级原因(不含零值 EscalationUnknown)。

func (EscalationReason) MarshalText

func (r EscalationReason) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (EscalationReason) String

func (r EscalationReason) String() string

String 返回升级原因的规范小写标识。

func (*EscalationReason) UnmarshalText

func (r *EscalationReason) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 EscalationUnknown。

type GuardrailDecision

type GuardrailDecision interface {
	Kind() DecisionKind
	Reason() string
	IsValid() bool
	ToVerdict() Verdict
	// contains filtered or unexported methods
}

GuardrailDecision 是护栏策略判定的封闭代数和类型(RFC §3.6),仅含三个不可变具体变体: *DecisionDeny、*DecisionNeedApproval 与 *DecisionAllow;由 xopsvet/sumexhaust 强制穷尽与 fail-closed default。

func EvaluateThreshold

func EvaluateThreshold(opRisk, threshold RiskLevel) GuardrailDecision

EvaluateThreshold 按单调安全格规则将 (opRisk, threshold) 映射为 GuardrailDecision: 任一侧无效返回 *DecisionDeny;opRisk >= threshold 返回 *DecisionNeedApproval;否则返回 *DecisionAllow。

func FoldDecisions

func FoldDecisions(decisions ...GuardrailDecision) GuardrailDecision

FoldDecisions 对一组护栏决策执行顺序无关的限制支配并半格折叠;空输入严格失败关闭返回 *DecisionDeny。

func JoinDecisions

func JoinDecisions(a, b GuardrailDecision) GuardrailDecision

JoinDecisions 按限制支配有界格合并两个护栏决策(Deny 吸收 NeedApproval 吸收 Allow)。 同类别 *DecisionNeedApproval 按 (SeverityRank DESC, reason ASC) 全序选取,确保高风险原因绝不被低风险原因遮蔽, 同时完整满足交换律、结合律、幂等律与单调律。

func NormalizeDecision

func NormalizeDecision(d GuardrailDecision) GuardrailDecision

NormalizeDecision 将任意 GuardrailDecision 归一化为有效不可变副本;nil/无效零值失败关闭为 *DecisionDeny。

func UnmarshalDecisionFrom

func UnmarshalDecisionFrom(dec *jsontext.Decoder) (GuardrailDecision, error)

UnmarshalDecisionFrom 从 Go 1.27 JSON/v2 流严格解码多态 GuardrailDecision; 对 JSON null、缺失 kind、非法变体字段组合均严格失败关闭返回 ErrInvalidDecision。

type NodeOverrideRule

type NodeOverrideRule struct {
	// contains filtered or unexported fields
}

NodeOverrideRule 表示单条经过语法与阈值校验的不可变节点护栏覆盖规则;零值恒无效并严格失败关闭。

func NewNodeOverrideRule

func NewNodeOverrideRule(pattern string, approvalThreshold RiskLevel) (NodeOverrideRule, error)

NewNodeOverrideRule 校验模式与风险阈值,构造一条仅收紧审批阈值的节点覆盖规则。

func NewNodeOverrideRuleWithFloor

func NewNodeOverrideRuleWithFloor(pattern string, approvalThreshold RiskLevel, decisionFloor DecisionKind) (NodeOverrideRule, error)

NewNodeOverrideRuleWithFloor 校验模式、审批阈值与强制决策下限,构造完整节点覆盖规则。

func (NodeOverrideRule) ApprovalThreshold

func (r NodeOverrideRule) ApprovalThreshold() RiskLevel

ApprovalThreshold 返回规则指定的审批阈值;无效时返回 RiskUnknown。

func (NodeOverrideRule) CombineSamePattern

func (r NodeOverrideRule) CombineSamePattern(other NodeOverrideRule) NodeOverrideRule

CombineSamePattern 对同模式的两条规则执行并半格收紧(最严阈值 + 最严决策下限);非法或异模式返回零值。

func (NodeOverrideRule) DecisionFloor

func (r NodeOverrideRule) DecisionFloor() DecisionKind

DecisionFloor 返回规则指定的最低限制决策类别;无效时失败关闭返回 DecisionKindDeny。

func (NodeOverrideRule) Equal

func (r NodeOverrideRule) Equal(other NodeOverrideRule) bool

Equal 比较两条覆盖规则是否均有效且完全一致(零值永不相等)。

func (NodeOverrideRule) IsValid

func (r NodeOverrideRule) IsValid() bool

IsValid 报告规则是否已通过构造器校验。

func (NodeOverrideRule) IsZero

func (r NodeOverrideRule) IsZero() bool

IsZero 报告规则是否为无效零值。

func (NodeOverrideRule) MarshalJSONTo

func (r NodeOverrideRule) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值规则失败关闭。

func (NodeOverrideRule) Pattern

func (r NodeOverrideRule) Pattern() string

Pattern 返回节点匹配通配符模式。

func (*NodeOverrideRule) UnmarshalJSONFrom

func (r *NodeOverrideRule) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null 或缺失必需字段失败关闭并重置零值。

type NodeOverrides

type NodeOverrides struct {
	// contains filtered or unexported fields
}

NodeOverrides 表示按 pattern 排序并自动合并同模式冲突的不可变节点覆盖规则格集合(INV-E3 / RFC §3.6); 彻底消除 Go map 迭代序依赖,零值恒无效并失败关闭,空集合须经 EmptyNodeOverrides 显式构造。

func EmptyNodeOverrides

func EmptyNodeOverrides() NodeOverrides

EmptyNodeOverrides 返回显式为空且有效的 NodeOverrides(Join 运算单位元)。

func NewNodeOverrides

func NewNodeOverrides(rules ...NodeOverrideRule) (NodeOverrides, error)

NewNodeOverrides 校验并按规范顺序折叠一组规则为不可变 NodeOverrides,保证任意输入排列结果一致。

func NewNodeOverridesFromMap

func NewNodeOverridesFromMap(entries map[string]RiskLevel) (NodeOverrides, error)

NewNodeOverridesFromMap 将配置中的 map[pattern]RiskLevel 按确定性键序规范化为顺序无关的 NodeOverrides。

func (NodeOverrides) Equal

func (o NodeOverrides) Equal(other NodeOverrides) bool

Equal 比较两个 NodeOverrides 是否均有效且规则集完全相同。

func (NodeOverrides) EvaluateBatch

func (o NodeOverrides) EvaluateBatch(baseThreshold, opRisk RiskLevel, nodeIDs ...string) GuardrailDecision

EvaluateBatch 在全局基准阈值、操作风险与批量目标节点集合上执行严格单调且顺序无关的限制支配折叠(INV-E3): 始终从全局 EvaluateThreshold(opRisk, baseThreshold) 起步折叠,确保任意新增目标节点只会维持或收紧决策。

func (NodeOverrides) EvaluateNode

func (o NodeOverrides) EvaluateNode(baseThreshold, opRisk RiskLevel, nodeID string) GuardrailDecision

EvaluateNode 在基准阈值与操作风险下对单个目标节点求值(空 nodeID 走全局基准阈值,非法 nodeID 失败关闭为 Deny)。

func (NodeOverrides) IsValid

func (o NodeOverrides) IsValid() bool

IsValid 报告规则集是否经构造器初始化且全部规则有效。

func (NodeOverrides) IsZero

func (o NodeOverrides) IsZero() bool

IsZero 报告规则集是否为无效零值。

func (NodeOverrides) Join

Join 按严苛度并半格合并两个 NodeOverrides;任一侧无效返回零值,满足交换/结合/幂等/单调律。

func (NodeOverrides) Len

func (o NodeOverrides) Len() int

Len 返回已规范去重后的规则数量。

func (NodeOverrides) MarshalJSONTo

func (o NodeOverrides) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者),以规范排序数组编码;零值失败关闭。

func (NodeOverrides) ResolveBatchThreshold

func (o NodeOverrides) ResolveBatchThreshold(baseThreshold RiskLevel, nodeIDs ...string) (RiskLevel, error)

ResolveBatchThreshold 对批量目标节点执行单调严苛阈值折叠(INV-E3): 始终以全局 baseThreshold 初始化折叠,确保批量操作绝不因单个宽松节点覆盖而弱化全局策略。

func (NodeOverrides) ResolveThreshold

func (o NodeOverrides) ResolveThreshold(baseThreshold RiskLevel, nodeID string) (RiskLevel, error)

ResolveThreshold 计算单节点 nodeID 的有效审批阈值(INV-E3):空 nodeID 走全局 baseThreshold, 非空时前置校验 nodeID 并遍历全部命中规则按 StrictestThreshold 折叠,彻底消除规则顺序依赖。

func (NodeOverrides) Rules

func (o NodeOverrides) Rules() []NodeOverrideRule

Rules 返回按 pattern 升序排列的规则防御性拷贝。

func (*NodeOverrides) UnmarshalJSONFrom

func (o *NodeOverrides) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;失败时重置为零值并失败关闭。

type OperationBinding

type OperationBinding struct {
	// contains filtered or unexported fields
}

OperationBinding 是不可变的操作规范绑定快照(INV-E4 / INV-E5),锁定能力、工具/动作、目标、 规范路径、命令/计划摘要与排序参数,并经 //xops:canonicalhash 由 xopsvet/digestcover 校验全字段覆盖。

func NewOperationBinding

func NewOperationBinding(spec OperationBindingSpec) (OperationBinding, error)

NewOperationBinding 校验并构造规范排序去重后的不可变 OperationBinding。

func (OperationBinding) Action

func (b OperationBinding) Action() string

Action 返回绑定的具体子动作标识。

func (OperationBinding) CanonicalPaths

func (b OperationBinding) CanonicalPaths() []string

CanonicalPaths 返回排序去重后的规范路径防御性拷贝。

func (OperationBinding) Capability

func (b OperationBinding) Capability() CapabilityKind

Capability 返回绑定的能力类别;无效零值返回 CapabilityInvalid。

func (OperationBinding) CommandDigest

func (b OperationBinding) CommandDigest() algebraic.Option[Digest]

CommandDigest 返回可选命令计划 SHA-256 摘要。

func (OperationBinding) Digest

func (b OperationBinding) Digest() (Digest, error)

Digest 计算并返回 OperationBinding 的确定性 SHA-256 规范摘要。

func (OperationBinding) Endpoint

Endpoint 返回可选强类型目标 SSH 端点。

func (OperationBinding) Equal

func (b OperationBinding) Equal(other OperationBinding) bool

Equal 严格比对两个 OperationBinding 是否均有效且全部字段完全一致(无效零值永不相等)。

func (OperationBinding) IsValid

func (b OperationBinding) IsValid() bool

IsValid 报告 OperationBinding 是否经构造器有效初始化。

func (OperationBinding) IsZero

func (b OperationBinding) IsZero() bool

IsZero 报告 OperationBinding 是否为无效零值。

func (OperationBinding) MarshalJSONTo

func (b OperationBinding) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);配合 Deterministic(true) 产出确定性 JSON,零值失败关闭。

func (OperationBinding) NodeID

func (b OperationBinding) NodeID() string

NodeID 返回主目标节点标识(全局操作为空串)。

func (OperationBinding) NodeIDs

func (b OperationBinding) NodeIDs() []string

NodeIDs 返回排序去重后的多目标节点防御性拷贝。

func (OperationBinding) Param

func (b OperationBinding) Param(key string) (string, bool)

Param 按键查询单个绑定参数;无效绑定或键不存在返回 ("", false)。

func (OperationBinding) Parameters

func (b OperationBinding) Parameters() map[string]string

Parameters 返回规范参数映射的全新拷贝,隔离外部修改。

func (OperationBinding) PlanDigest

func (b OperationBinding) PlanDigest() algebraic.Option[Digest]

PlanDigest 返回可选连接计划 Merkle SHA-256 摘要。

func (OperationBinding) RecursivePaths

func (b OperationBinding) RecursivePaths() []string

RecursivePaths 返回排序去重后的递归目录路径防御性拷贝。

func (OperationBinding) Tool

func (b OperationBinding) Tool() string

Tool 返回绑定的工具或用例标识。

func (*OperationBinding) UnmarshalJSONFrom

func (b *OperationBinding) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或非法值失败关闭并重置零值。

func (OperationBinding) WriteCanonical

func (b OperationBinding) WriteCanonical(w io.Writer) error

WriteCanonical 以零反射、长度前缀与域分离方式将 OperationBinding 全部字段写入 w(受 digestcover 校验)。

type OperationBindingSpec

type OperationBindingSpec struct {
	Capability     CapabilityKind
	Tool           string
	Action         string
	NodeID         string
	NodeIDs        []string
	Endpoint       algebraic.Option[netaddr.Endpoint]
	CanonicalPaths []string
	RecursivePaths []string
	CommandDigest  algebraic.Option[Digest]
	PlanDigest     algebraic.Option[Digest]
	Parameters     map[string]string
}

OperationBindingSpec 是构造不可变 OperationBinding 的显式入参规格。

type OperationID

type OperationID struct {
	// contains filtered or unexported fields
}

OperationID 表示单次安全授权、审批挑战与审计闭环的不可变操作唯一标识, 由 core/internal/foundation/trace.OpID 别名复用;零值恒无效并严格失败关闭。

func NewOperationIDFrom

func NewOperationIDFrom(entropy io.Reader) (OperationID, error)

NewOperationIDFrom 从调用方显式注入的熵源读取 16 字节并构造 OperationID(零隐式 crypto/rand)。

func OperationIDFromBytes

func OperationIDFromBytes(raw [operationIDEntropyBytes]byte) OperationID

OperationIDFromBytes 将 16 字节原始熵确定性编码为 32 位小写十六进制 OperationID。

func ParseOperationID

func ParseOperationID(raw string) (OperationID, error)

ParseOperationID 校验并构造 OperationID;仅接受长度 1..128 的可打印非空白 ASCII(0x21..0x7E)。

func (OperationID) AppendText

func (id OperationID) AppendText(b []byte) ([]byte, error)

AppendText、MarshalText 与 UnmarshalText 实现 OperationID 的值接收者文本编解码(零值与非法输入失败关闭)。

func (OperationID) Compare

func (id OperationID) Compare(other OperationID) int

func (OperationID) Equal

func (id OperationID) Equal(other OperationID) bool

func (OperationID) IsValid

func (id OperationID) IsValid() bool

IsValid、IsZero、String、Equal 与 Compare 实现 OperationID 的失败关闭语义与确定性全序(无效零值永不相等)。

func (OperationID) IsZero

func (id OperationID) IsZero() bool

func (OperationID) MarshalText

func (id OperationID) MarshalText() ([]byte, error)

func (OperationID) String

func (id OperationID) String() string

func (*OperationID) UnmarshalText

func (id *OperationID) UnmarshalText(text []byte) error

type RiskLevel

type RiskLevel uint8

RiskLevel 表示操作风险等级与审批阈值使用的有界安全格(RFC §3.6): 零值恒为 RiskUnknown(0),在操作风险并半格 Join 与阈值严苛度并半格 StrictestThreshold 中均充当最高吸收顶元, 绝不静默视作低风险,且序列化边界严格拒绝 RiskUnknown。

const (
	RiskUnknown   RiskLevel = iota // 零值未设置/未知风险(全格吸收态,严禁视作低风险)
	RiskSafe                       // 只读无副作用低风险(操作风险并半格单位底元)
	RiskModerate                   // 可恢复写操作或受保护路径读取(中等风险)
	RiskDangerous                  // 破坏性写、任意命令执行、盘符根或高危隧道(最高有效风险)
)

func FoldRisks

func FoldRisks(levels ...RiskLevel) RiskLevel

FoldRisks 对一组操作风险等级执行顺序无关的并半格折叠;空输入严格失败关闭返回 RiskUnknown。

func FoldThresholds

func FoldThresholds(thresholds ...RiskLevel) RiskLevel

FoldThresholds 对一组审批阈值执行顺序无关的严苛度并半格折叠;空输入严格失败关闭返回 RiskUnknown。

func ParseRiskLevel

func ParseRiskLevel(raw string) (RiskLevel, error)

ParseRiskLevel 严格解析规范小写风险等级文本("safe"、"moderate"、"dangerous")。

func (RiskLevel) AppendText

func (r RiskLevel) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对 RiskUnknown 及越界值失败关闭。

func (RiskLevel) CompareSeverity

func (r RiskLevel) CompareSeverity(other RiskLevel) int

CompareSeverity 按操作严重度顺序比较两个 RiskLevel。

func (RiskLevel) CompareThresholdStrictness

func (r RiskLevel) CompareThresholdStrictness(other RiskLevel) int

CompareThresholdStrictness 按审批阈值严苛度顺序比较两个 RiskLevel。

func (RiskLevel) IsValid

func (r RiskLevel) IsValid() bool

IsValid 报告 r 是否为明确有效的业务风险等级(RiskSafe / RiskModerate / RiskDangerous)。

func (RiskLevel) IsZero

func (r RiskLevel) IsZero() bool

IsZero 报告 r 是否处于零值未设置态(RiskUnknown)。

func (RiskLevel) Join

func (r RiskLevel) Join(other RiskLevel) RiskLevel

Join 计算操作风险并半格上确界(max 严重度);任一侧无效时吸收为 RiskUnknown。

func (RiskLevel) MarshalText

func (r RiskLevel) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (RiskLevel) Normalize

func (r RiskLevel) Normalize() RiskLevel

Normalize 将非法越界底层值折叠为 RiskUnknown,合法值保持不变。

func (RiskLevel) SeverityRank

func (r RiskLevel) SeverityRank() uint8

SeverityRank 返回操作风险严重度全序秩(Safe=1 < Moderate=2 < Dangerous=3 < Unknown/非法=4)。

func (RiskLevel) StrictestThreshold

func (r RiskLevel) StrictestThreshold(other RiskLevel) RiskLevel

StrictestThreshold 计算审批阈值严苛度并半格上确界(有效阈值取 min,RiskUnknown 吸收)。

func (RiskLevel) String

func (r RiskLevel) String() string

String 返回规范小写文本("safe"、"moderate"、"dangerous" 或 "unknown")。

func (RiskLevel) ThresholdStrictnessRank

func (r RiskLevel) ThresholdStrictnessRank() uint8

ThresholdStrictnessRank 返回审批阈值严苛度全序秩(Dangerous=1 < Moderate=2 < Safe=3 < Unknown/非法=4)。

func (*RiskLevel) UnmarshalText

func (r *RiskLevel) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 RiskUnknown 并失败关闭。

type ScopeEscalationResult

type ScopeEscalationResult struct {
	// contains filtered or unexported fields
}

ScopeEscalationResult 保存 InspectScopeEscalation 的纯函数判定结论与审计诊断详情; 内置正向有效门控 valid bool,未初始化零值调用 Escalated() 时严格失败关闭返回 true。

func InspectScopeEscalation

func InspectScopeEscalation(lexical, canonical ScopeSnapshot) ScopeEscalationResult

InspectScopeEscalation 对 lexical 与 canonical 快照执行完整多维升级检测,返回确定性诊断结果。

func (ScopeEscalationResult) AddedProtectedPaths

func (r ScopeEscalationResult) AddedProtectedPaths() []string

AddedProtectedPaths 返回规范化阶段新增或重定向命中的受保护路径列表防御性拷贝。

func (ScopeEscalationResult) Equal

Equal 严格比对两个 ScopeEscalationResult 是否均有效且全部结论字段一致(无效零值永不相等)。

func (ScopeEscalationResult) Escalated

func (r ScopeEscalationResult) Escalated() bool

Escalated 报告规范化后的作用域相较词法预检是否发生升级、受保护重定向或输入异常;零值失败关闭返回 true。

func (ScopeEscalationResult) HasReason

func (r ScopeEscalationResult) HasReason(target EscalationReason) bool

HasReason 报告结果中是否包含指定的升级原因。

func (ScopeEscalationResult) IsValid

func (r ScopeEscalationResult) IsValid() bool

IsValid 报告 ScopeEscalationResult 是否由有效判定或反序列化产生。

func (ScopeEscalationResult) IsZero

func (r ScopeEscalationResult) IsZero() bool

IsZero 报告 ScopeEscalationResult 是否为未初始化无效零值。

func (ScopeEscalationResult) MarshalJSONTo

func (r ScopeEscalationResult) MarshalJSONTo(enc *jsontext.Encoder) error

func (ScopeEscalationResult) Reasons

Reasons 返回按固定顺序排列的升级原因防御性拷贝;零值返回 EscalationInvalidInput。

func (*ScopeEscalationResult) UnmarshalJSONFrom

func (r *ScopeEscalationResult) UnmarshalJSONFrom(dec *jsontext.Decoder) error

type ScopeSnapshot

type ScopeSnapshot struct {
	// contains filtered or unexported fields
}

ScopeSnapshot 表示词法预检(Round 1)或远端软链规范化(Round 2)阶段的不可变安全作用域快照; 内部路径按字典序规范排序并折叠重复项,零值恒无效并在 CanonicalScopeEscalated 中无条件失败关闭返回 true。

func FoldScopeSnapshots

func FoldScopeSnapshots(snaps ...ScopeSnapshot) ScopeSnapshot

FoldScopeSnapshots 对一组 ScopeSnapshot 执行顺序无关的代数格折叠;空输入失败关闭返回零值。

func NewScopeSnapshot

func NewScopeSnapshot(spec ScopeSnapshotSpec) (ScopeSnapshot, error)

NewScopeSnapshot 校验并构造不可变 ScopeSnapshot。

func (ScopeSnapshot) Capability

func (s ScopeSnapshot) Capability() CapabilityKind

Capability 返回快照绑定的能力类别。

func (ScopeSnapshot) Decision

func (s ScopeSnapshot) Decision() GuardrailDecision

Decision 返回快照对应的护栏决策副本;无效时失败关闭返回 *DecisionDeny。

func (ScopeSnapshot) Endpoint

Endpoint 返回可选目标端点。

func (ScopeSnapshot) Equal

func (s ScopeSnapshot) Equal(other ScopeSnapshot) bool

Equal 严格比对两个 ScopeSnapshot 是否均有效且所有字段完全一致(无效零值永不相等)。

func (ScopeSnapshot) HasProtectedPath

func (s ScopeSnapshot) HasProtectedPath() bool

HasProtectedPath 报告快照中是否存在任意命中受保护分区的路径。

func (ScopeSnapshot) IsValid

func (s ScopeSnapshot) IsValid() bool

IsValid 报告 ScopeSnapshot 是否完整有效。

func (ScopeSnapshot) IsZero

func (s ScopeSnapshot) IsZero() bool

IsZero 报告 ScopeSnapshot 是否为无效零值。

func (ScopeSnapshot) Join

Join 将同身份两份作用域快照按有界格折叠(Verdict Meet、Risk Join、Decision Join、Paths 并集折叠)。 任一快照无效或身份漂移时失败关闭返回零值;严格满足交换/结合/幂等律。

func (ScopeSnapshot) MarshalJSONTo

func (s ScopeSnapshot) MarshalJSONTo(enc *jsontext.Encoder) error

func (ScopeSnapshot) Paths

func (s ScopeSnapshot) Paths() []ScopedPath

Paths 返回规范排序去重后的作用域路径防御性拷贝。

func (ScopeSnapshot) Risk

func (s ScopeSnapshot) Risk() RiskLevel

Risk 返回快照对应的风险等级;无效时失败关闭返回 RiskUnknown。

func (ScopeSnapshot) TargetNode

func (s ScopeSnapshot) TargetNode() string

TargetNode 返回快照绑定的目标节点标识。

func (*ScopeSnapshot) UnmarshalJSONFrom

func (s *ScopeSnapshot) UnmarshalJSONFrom(dec *jsontext.Decoder) error

func (ScopeSnapshot) Verdict

func (s ScopeSnapshot) Verdict() Verdict

Verdict 返回快照对应的二值判定;无效时失败关闭返回 VerdictDeny。

type ScopeSnapshotSpec

type ScopeSnapshotSpec struct {
	Capability CapabilityKind
	TargetNode string
	Endpoint   algebraic.Option[netaddr.Endpoint]
	Verdict    Verdict
	Risk       RiskLevel
	Decision   GuardrailDecision
	Paths      []ScopedPath
}

ScopeSnapshotSpec 是构造不可变 ScopeSnapshot 的显式入参规格。

type ScopedPath

type ScopedPath struct {
	// contains filtered or unexported fields
}

ScopedPath 表示单条进入安全作用域判定的不可变路径条目及其受保护分区集合; 同路径按 recursive 逻辑或与受保护分区集合并集折叠,零值恒无效并失败关闭。

func NewScopedPath

func NewScopedPath(path string, recursive bool, protectedZones ...string) (ScopedPath, error)

NewScopedPath 校验路径与受保护分区标签并构造不可变 ScopedPath。

func (ScopedPath) Equal

func (p ScopedPath) Equal(other ScopedPath) bool

Equal 严格比对两个 ScopedPath 是否均有效且完全一致(无效零值永不相等)。

func (ScopedPath) IsProtected

func (p ScopedPath) IsProtected() bool

IsProtected 报告该路径条目是否命中至少一个受保护分区。

func (ScopedPath) IsRecursive

func (p ScopedPath) IsRecursive() bool

IsRecursive 报告该路径条目是否覆盖递归后代目录。

func (ScopedPath) IsValid

func (p ScopedPath) IsValid() bool

IsValid 报告 ScopedPath 是否有效。

func (ScopedPath) IsZero

func (p ScopedPath) IsZero() bool

IsZero 报告 ScopedPath 是否为无效零值。

func (ScopedPath) JoinSamePath

func (p ScopedPath) JoinSamePath(other ScopedPath) ScopedPath

JoinSamePath 对同路径的两条记录执行并半格合并(recursive || 与受保护分区并集);非法或异路径返回零值。

func (ScopedPath) MarshalJSONTo

func (p ScopedPath) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 与 UnmarshalJSONFrom 实现 ScopedPath、ScopeSnapshot 与 ScopeEscalationResult 的严格 json/v2 编解码(拒绝零值、null、未知字段与缺失必需字段)。

func (ScopedPath) Path

func (p ScopedPath) Path() string

Path 返回规范化路径文本。

func (ScopedPath) ProtectedZones

func (p ScopedPath) ProtectedZones() []string

ProtectedZones 返回按字典序排列去重后的受保护分区防御性拷贝。

func (*ScopedPath) UnmarshalJSONFrom

func (p *ScopedPath) UnmarshalJSONFrom(dec *jsontext.Decoder) error

type TraceID

type TraceID struct {
	// contains filtered or unexported fields
}

TraceID 表示单次请求链路的不可变全局追踪唯一标识, 由 core/internal/foundation/trace 别名复用(零拷贝互通),供 core/ports 与 core/events 公开使用; 零值恒无效并严格失败关闭。

func NewTraceIDFrom

func NewTraceIDFrom(entropy io.Reader) (TraceID, error)

NewTraceIDFrom 从调用方显式注入的熵源读取 16 字节并构造 TraceID(零隐式 crypto/rand)。

func ParseTraceID

func ParseTraceID(raw string) (TraceID, error)

ParseTraceID 校验并构造 TraceID;仅接受长度 1..128 的可打印非空白 ASCII(0x21..0x7E)。

func TraceIDFromBytes

func TraceIDFromBytes(raw [operationIDEntropyBytes]byte) TraceID

TraceIDFromBytes 将 16 字节原始熵确定性编码为 32 位小写十六进制 TraceID。

func (TraceID) AppendText

func (id TraceID) AppendText(b []byte) ([]byte, error)

AppendText、MarshalText 与 UnmarshalText 实现 TraceID 的值接收者文本编解码(零值与非法输入失败关闭)。

func (TraceID) Compare

func (id TraceID) Compare(other TraceID) int

func (TraceID) Equal

func (id TraceID) Equal(other TraceID) bool

func (TraceID) IsValid

func (id TraceID) IsValid() bool

IsValid、IsZero、String、Equal 与 Compare 实现 TraceID 的失败关闭语义与确定性全序(无效零值永不相等)。

func (TraceID) IsZero

func (id TraceID) IsZero() bool

func (TraceID) MarshalText

func (id TraceID) MarshalText() ([]byte, error)

func (TraceID) String

func (id TraceID) String() string

func (*TraceID) UnmarshalText

func (id *TraceID) UnmarshalText(text []byte) error

type Verdict

type Verdict uint8

Verdict 表示失败关闭的二值安全判定交半格(INV-E1 / RFC §3.6): 零值恒为 VerdictDeny(0,吸收底元);仅显式 VerdictAllow(1)代表放行(单位顶元);越界值一律视为拒绝。

const (
	VerdictDeny  Verdict = 0 // 零值失败关闭判定(交半格吸收底元)
	VerdictAllow Verdict = 1 // 显式允许执行(交半格单位顶元)
)

func Decide

func Decide(fn func() (Verdict, error)) Verdict

Decide 同步执行安全判定闭包 fn,并将 nil 闭包、任意错误或非 VerdictAllow 值失败关闭为 VerdictDeny。

func FoldVerdicts

func FoldVerdicts(verdicts ...Verdict) Verdict

FoldVerdicts 对一组判定执行顺序无关的交半格折叠;空输入严格失败关闭返回 VerdictDeny。

func ParseVerdict

func ParseVerdict(raw string) (Verdict, error)

ParseVerdict 严格解析规范小写判定文本("deny" 或 "allow");其余输入一律失败关闭。

func VerdictFromError

func VerdictFromError(v Verdict, err error) Verdict

VerdictFromError 将 (Verdict, error) 折叠为纯 Verdict:任意非 nil 错误或非 VerdictAllow 值均返回 VerdictDeny。

func (Verdict) Allowed

func (v Verdict) Allowed() bool

Allowed 报告 v 是否为显式 VerdictAllow(零值与越界值恒返回 false)。

func (Verdict) AppendText

func (v Verdict) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对非法越界值失败关闭。

func (Verdict) Compare

func (v Verdict) Compare(other Verdict) int

Compare 定义 Verdict 上的确定性全序(VerdictDeny/非法值 < VerdictAllow)。

func (Verdict) Denied

func (v Verdict) Denied() bool

Denied 报告 v 是否拒绝执行(含零值与一切非法越界值)。

func (Verdict) IsValid

func (v Verdict) IsValid() bool

IsValid 报告 v 是否为已定义的合法 Verdict。

func (Verdict) IsZero

func (v Verdict) IsZero() bool

IsZero 报告 v 是否处于零值拒绝态(VerdictDeny)。

func (Verdict) MarshalText

func (v Verdict) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (Verdict) Meet

func (v Verdict) Meet(other Verdict) Verdict

Meet 计算交半格下确界:仅双方均为 VerdictAllow 时返回 VerdictAllow,否则返回 VerdictDeny。

func (Verdict) Normalize

func (v Verdict) Normalize() Verdict

Normalize 将非法越界底层值折叠为 VerdictDeny,合法值保持不变。

func (Verdict) String

func (v Verdict) String() string

String 返回规范小写文本("deny"、"allow");非法越界值返回 "deny(invalid)"。

func (*Verdict) UnmarshalText

func (v *Verdict) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;解析失败时重置为 VerdictDeny 并失败关闭。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL