{"modulePath":"goark.dev/security","version":"v0.0.0-20261007131815-ff4cbb205432","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpsign\n\nPackage httpsign 实现 RFC 9421 的有界 HMAC-SHA256 请求签名配置，包含正文摘要与防重放。\n\n## Functions\n\n```go\nfunc Sign(r *http.Request, key Key, options ...SignOptions) error\n```\nSign 签署方法、完整目标、类型与正文摘要，选项只能传零或一个。 客户端仅需 ID 和 Secret；Principal 只用于服务端可信密钥到身份的映射。\n\n## Types\n\n```go\ntype Config struct {\n\tRealm                string\n\tKeys                 []Key\n\tKeyStore             Keys\n\tReplays              dpop.Store\n\tMaxAge, Leeway       time.Duration\n\tMaxBodyBytes         int64\n\tMaxKeys, MaxRequests int\n\tAllowHTTP            bool\n}\n```\nConfig 限定可信密钥、重放存储、时间窗口与正文预算。\n\n```go\ntype Key struct {\n\tID        string\n\tSecret    []byte\n\tPrincipal security.Principal\n}\n```\nKey 保存调用方签名密钥及最小权限主体，密钥至少 32 字节。\n\n```go\nfunc (Key) GoString() string\n```\nGoString 隐藏 Go 格式化输出中的签名密钥。\n\n```go\nfunc (Key) String() string\n```\nString 隐藏签名密钥。\n\n```go\ntype Keys interface {\n\tGet(context.Context, string) (Key, error)\n}\n```\nKeys 提供登记密钥，调用方可实现外部密钥仓库。\n\n```go\ntype MemoryKeys struct {\n\t// contains filtered or unexported fields\n}\n```\nMemoryKeys 保存有界的独立密钥副本，支持原子轮换。\n\n```go\nfunc NewMemoryKeys(max int) (*MemoryKeys, error)\n```\nNewMemoryKeys 创建默认容量为 256 的内存密钥仓库。\n\n```go\nfunc (m *MemoryKeys) Close()\n```\nClose 清除自有密钥内容并停止后续操作。\n\n```go\nfunc (m *MemoryKeys) Delete(ctx context.Context, id string) error\n```\nDelete 撤销可信调用方密钥。\n\n```go\nfunc (m *MemoryKeys) Get(ctx context.Context, id string) (Key, error)\n```\nGet 返回独立密钥副本，缺失密钥不能回退为匿名认证。\n\n```go\nfunc (m *MemoryKeys) Put(ctx context.Context, k Key) error\n```\nPut 新增或原子轮换可信密钥，复制密钥避免调用方修改。\n\n```go\ntype Service struct {\n\t// contains filtered or unexported fields\n}\n```\nService 通过既有安全 Filter 验证签名与重放，外部存储由调用方拥有。\n\n```go\nfunc New(c Config) (*Service, error)\n```\nNew 创建默认一分钟窗口、一 MiB 正文预算的签名验证器。\n\n```go\nfunc (s *Service) Authenticate(ctx context.Context, c security.Credential) (security.Principal, error)\n```\nAuthenticate 校验签名、目标、时间及 nonce，成功后才原子登记重放状态。\n\n```go\nfunc (s *Service) Close() error\n```\nClose 仅释放自有密钥与重放仓库。\n\n```go\nfunc (s *Service) Credentials(r *http.Request) (security.Credential, error)\n```\nCredentials 验证完整正文摘要并恢复请求体，不读取转发目标或信任客户端身份头。\n\n```go\ntype SignOptions struct {\n\tLifetime     time.Duration\n\tMaxBodyBytes int64\n\tAllowHTTP    bool\n}\n```\nSignOptions 可覆盖一分钟期限和一 MiB 正文预算。\n\n","path":"goark.dev/security/httpsign","name":"httpsign","synopsis":"Package httpsign 实现 RFC 9421 的有界 HMAC-SHA256 请求签名配置，包含正文摘要与防重放。","isRedistributable":true}
