Skip to content

Commit a99e830

Browse files
wxiaoguangdelvh
andauthored
Apply suggestions from code review
Co-authored-by: delvh <[email protected]>
1 parent cb29e30 commit a99e830

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

modules/secret/secret.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func AesEncrypt(key, text []byte) ([]byte, error) {
2626
ciphertext := make([]byte, aes.BlockSize+len(b))
2727
iv := ciphertext[:aes.BlockSize]
2828
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
29-
return nil, fmt.Errorf("AesEncrypt unable to read iv: %w", err)
29+
return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err)
3030
}
3131
cfb := cipher.NewCFBEncrypter(block, iv)
3232
cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
@@ -48,7 +48,7 @@ func AesDecrypt(key, text []byte) ([]byte, error) {
4848
cfb.XORKeyStream(text, text)
4949
data, err := base64.StdEncoding.DecodeString(string(text))
5050
if err != nil {
51-
return nil, fmt.Errorf("AesDecrypt invalid decrtyped base64 string: %w", err)
51+
return nil, fmt.Errorf("AesDecrypt invalid decrypted base64 string: %w", err)
5252
}
5353
return data, nil
5454
}
@@ -69,11 +69,11 @@ func DecryptSecret(key, cipherHex string) (string, error) {
6969
keyHash := sha256.Sum256([]byte(key))
7070
ciphertext, err := hex.DecodeString(cipherHex)
7171
if err != nil {
72-
return "", fmt.Errorf("failed to decrtyp by secret, invalid hex string: %w", err)
72+
return "", fmt.Errorf("failed to decrypt by secret, invalid hex string: %w", err)
7373
}
7474
plaintext, err := AesDecrypt(keyHash[:], ciphertext)
7575
if err != nil {
76-
return "", fmt.Errorf("failed to decrtyp by secret, secret key (SECRET_KEY) might be incorrect: %w", err)
76+
return "", fmt.Errorf("failed to decrypt by secret, secret key (SECRET_KEY) might be incorrect: %w", err)
7777
}
7878
return string(plaintext), nil
7979
}

0 commit comments

Comments
 (0)