refactor(crypto): 拆分签发与验证,新增 sign 包
- crypto 仅保留验证:验签、信任链、CRL/verdict、指纹 - 新增 sign 包:SignToken/SignBundle、密钥生成、私钥加解密 - TrustChain 移除 SignBundle 方法,改由 Bundle() 导出快照, 避免反射可达性把 SignToken 链入纯验证二进制 - Bundle 快照单次读锁,修复旧 SignBundle 递归读锁死锁窗口 - 新增 golden token 与 go tool nm 符号级回归测试
This commit is contained in:
21 files changed
+461
-168
No files matched your search
@@ -0,0 +1,20 @@
|
||||
package sign
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"fmt"
|
||||
|
||||
"git.wxccs.org/EntitleForge/EntitleForge-SDK-go/license"
|
||||
)
|
||||
|
||||
// SignToken 以 Ed25519 私钥签发三段式 token。
|
||||
// typ 决定封装类型(license/lease/trust/crl/bundle),kid 写入 header。
|
||||
func SignToken(priv ed25519.PrivateKey, kid, typ string, payload []byte) (string, error) {
|
||||
if len(priv) != ed25519.PrivateKeySize {
|
||||
return "", fmt.Errorf("sign: 私钥长度非法")
|
||||
}
|
||||
h := license.Header{V: license.FormatVersion, Alg: license.AlgEd25519, Kid: kid, Typ: typ}
|
||||
return license.Encode(h, payload, func(content string) ([]byte, error) {
|
||||
return ed25519.Sign(priv, []byte(content)), nil
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user