refactor: naming cleanup and crypto package improvements (#551)

* refactor: naming cleanup across all packages
This commit is contained in:
Roger
2026-04-05 16:51:56 +08:00
committed by GitHub
parent 4af2ded428
commit 410bffe643
49 changed files with 716 additions and 510 deletions
+8 -5
View File
@@ -12,14 +12,17 @@ const (
// CipherDPAPI is pre-Chrome 80 raw DPAPI encryption (no version prefix).
CipherDPAPI CipherVersion = "dpapi"
// versionPrefixLen is the byte length of the version prefix ("v10", "v20").
versionPrefixLen = 3
)
// DetectVersion identifies the encryption version from a ciphertext prefix.
func DetectVersion(ciphertext []byte) CipherVersion {
if len(ciphertext) < 3 {
if len(ciphertext) < versionPrefixLen {
return CipherDPAPI
}
prefix := string(ciphertext[:3])
prefix := string(ciphertext[:versionPrefixLen])
switch prefix {
case "v10":
return CipherV10
@@ -30,12 +33,12 @@ func DetectVersion(ciphertext []byte) CipherVersion {
}
}
// StripPrefix removes the version prefix (e.g. "v10") from ciphertext.
// stripPrefix removes the version prefix (e.g. "v10") from ciphertext.
// Returns the ciphertext unchanged if no known prefix is found.
func StripPrefix(ciphertext []byte) []byte {
func stripPrefix(ciphertext []byte) []byte {
ver := DetectVersion(ciphertext)
if ver == CipherV10 || ver == CipherV20 {
return ciphertext[3:]
return ciphertext[versionPrefixLen:]
}
return ciphertext
}