package model import ( "time" core "git.yuntuo.hk/k2safe/orbit/model" ) // Credential 表示命名空间凭据,保存认证摘要、授权范围及可选的当前 Token 密文。 // 对应表 orbit_credentials;这是服务端持久化模型,不直接作为 API 响应。 type Credential struct { // Record 包含命名空间、记录标识、并发版本和 UTC 时间。 core.Record // Name 可读名称,唯一性范围由对应数据表约束。 Name string `db:"name"` // SecretDigest 凭据秘密的 SHA-256 摘要,用于业务认证,不输出原文。 SecretDigest core.Digest `db:"secret_digest"` // SecretKeyID 当前 Token 密文使用的主密钥标识;空表示尚未保管,与密文同时为空。 SecretKeyID *string `db:"secret_key_id"` // SecretCiphertext AES-256-GCM nonce 与认证密文,最多 1024 字节;仅管理员接口可解密。 SecretCiphertext []byte `db:"secret_ciphertext"` // PreviousSecretDigest 上一代秘密摘要;仅过渡期使用,空表示未保留旧令牌。 PreviousSecretDigest *core.Digest `db:"previous_secret_digest"` // PreviousValidUntil 旧令牌的固定 UTC 截止;不晚于原到期时间,与旧摘要同时为空或非空。 PreviousValidUntil *time.Time `db:"previous_valid_until"` // Permissions 授权范围的 JSON 快照,必须由服务端解释和校验。 Permissions core.JSON `db:"permissions"` // ExpiresAt 凭据过期时间,统一 UTC;为空表示没有配置到期时间。 ExpiresAt *time.Time `db:"expires_at"` // RevokedAt 撤销时间;为空表示尚未撤销。 RevokedAt *time.Time `db:"revoked_at"` } func (Credential) TableName() string { return "orbit_credentials" }