refactor: extract magic numbers to named constants for mnd lint compliance

This commit is contained in:
ryan
2026-06-09 13:44:29 +08:00
parent b05d26c9c6
commit e06f76436e
24 changed files with 650 additions and 440 deletions
+5 -2
View File
@@ -29,6 +29,9 @@ import (
"io"
)
// aesKeyLength AES-256 密钥字节长度
const aesKeyLength = 32
// Encrypt 使用 SignKey 加密字符串数据
// signKey: 64 字符 hex 编码的密钥(对应 32 字节,用于 AES-256)
// plaintext: 要加密的明文字符串
@@ -56,7 +59,7 @@ func encryptBytes(signKey string, plaintext []byte) (string, error) {
if err != nil {
return "", fmt.Errorf(errInvalidSignKey, err)
}
if len(key) != 32 {
if len(key) != aesKeyLength {
return "", errors.New(errSignKeyLengthInvalid)
}
@@ -92,7 +95,7 @@ func decryptBytes(signKey string, ciphertext string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf(errInvalidSignKey, err)
}
if len(key) != 32 {
if len(key) != aesKeyLength {
return nil, errors.New(errSignKeyLengthInvalid)
}