summaryrefslogtreecommitdiffstats
path: root/modules/util
diff options
context:
space:
mode:
Diffstat (limited to 'modules/util')
-rw-r--r--modules/util/legacy.go53
-rw-r--r--modules/util/legacy_test.go20
2 files changed, 0 insertions, 73 deletions
diff --git a/modules/util/legacy.go b/modules/util/legacy.go
index 2ea293a2be..2d4de01949 100644
--- a/modules/util/legacy.go
+++ b/modules/util/legacy.go
@@ -4,10 +4,6 @@
package util
import (
- "crypto/aes"
- "crypto/cipher"
- "crypto/rand"
- "errors"
"io"
"os"
)
@@ -40,52 +36,3 @@ func CopyFile(src, dest string) error {
}
return os.Chmod(dest, si.Mode())
}
-
-// AESGCMEncrypt (from legacy package): encrypts plaintext with the given key using AES in GCM mode. should be replaced.
-func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) {
- block, err := aes.NewCipher(key)
- if err != nil {
- return nil, err
- }
-
- gcm, err := cipher.NewGCM(block)
- if err != nil {
- return nil, err
- }
-
- nonce := make([]byte, gcm.NonceSize())
- if _, err := rand.Read(nonce); err != nil {
- return nil, err
- }
-
- ciphertext := gcm.Seal(nil, nonce, plaintext, nil)
- return append(nonce, ciphertext...), nil
-}
-
-// AESGCMDecrypt (from legacy package): decrypts ciphertext with the given key using AES in GCM mode. should be replaced.
-func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error) {
- block, err := aes.NewCipher(key)
- if err != nil {
- return nil, err
- }
-
- gcm, err := cipher.NewGCM(block)
- if err != nil {
- return nil, err
- }
-
- size := gcm.NonceSize()
- if len(ciphertext)-size <= 0 {
- return nil, errors.New("ciphertext is empty")
- }
-
- nonce := ciphertext[:size]
- ciphertext = ciphertext[size:]
-
- plainText, err := gcm.Open(nil, nonce, ciphertext, nil)
- if err != nil {
- return nil, err
- }
-
- return plainText, nil
-}
diff --git a/modules/util/legacy_test.go b/modules/util/legacy_test.go
index e732094c29..b7991bd365 100644
--- a/modules/util/legacy_test.go
+++ b/modules/util/legacy_test.go
@@ -4,8 +4,6 @@
package util
import (
- "crypto/aes"
- "crypto/rand"
"fmt"
"os"
"testing"
@@ -37,21 +35,3 @@ func TestCopyFile(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, testContent, dstContent)
}
-
-func TestAESGCM(t *testing.T) {
- t.Parallel()
-
- key := make([]byte, aes.BlockSize)
- _, err := rand.Read(key)
- assert.NoError(t, err)
-
- plaintext := []byte("this will be encrypted")
-
- ciphertext, err := AESGCMEncrypt(key, plaintext)
- assert.NoError(t, err)
-
- decrypted, err := AESGCMDecrypt(key, ciphertext)
- assert.NoError(t, err)
-
- assert.Equal(t, plaintext, decrypted)
-}