From 6cb3c620dc2a510eb70adfb72833258a37e21f02 Mon Sep 17 00:00:00 2001 From: Lz Date: Thu, 11 Apr 2024 20:27:45 +0800 Subject: [PATCH] chore(deepsource): fixed warnings --- auth_test.go | 2 +- crypto.go | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/auth_test.go b/auth_test.go index d7e92e5..83aed94 100644 --- a/auth_test.go +++ b/auth_test.go @@ -18,7 +18,7 @@ func createAuthTest(file string) *Auth { dbTest := sqle.Open(db) - //dbTest.SetMaxOpenConns(1) + // dbTest.SetMaxOpenConns(1) authTest := NewAuth(dbTest, WithPrefix("test_"), diff --git a/crypto.go b/crypto.go index dab3750..32e121e 100644 --- a/crypto.go +++ b/crypto.go @@ -54,27 +54,27 @@ func getAESKey(key string) []byte { func encryptText(plainText, key []byte) (string, error) { - //Create a new Cipher Block from the key + // Create a new Cipher Block from the key block, err := aes.NewCipher(key) if err != nil { return "", err } - //Create a new GCM - https://en.wikipedia.org/wiki/Galois/Counter_Mode - //https://golang.org/pkg/crypto/cipher/#NewGCM + // Create a new GCM - https://en.wikipedia.org/wiki/Galois/Counter_Mode + // https://golang.org/pkg/crypto/cipher/#NewGCM aesGCM, err := cipher.NewGCM(block) if err != nil { return "", err } - //Create a nonce. Nonce should be from GCM + // Create a nonce. Nonce should be from GCM nonce := make([]byte, aesGCM.NonceSize()) if _, err = io.ReadFull(rand.Reader, nonce); err != nil { return "", err } - //Encrypt the data using aesGCM.Seal - //Since we don't want to save the nonce somewhere else in this case, we add it as a prefix to the encrypted data. The first nonce argument in Seal is the prefix. + // Encrypt the data using aesGCM.Seal + // Since we don't want to save the nonce somewhere else in this case, we add it as a prefix to the encrypted data. The first nonce argument in Seal is the prefix. return hex.EncodeToString(aesGCM.Seal(nonce, nonce, plainText, nil)), nil } @@ -82,25 +82,25 @@ func decryptText(cipherText string, key []byte) (string, error) { enc, _ := hex.DecodeString(cipherText) - //Create a new Cipher Block from the key + // Create a new Cipher Block from the key block, err := aes.NewCipher(key) if err != nil { return "", err } - //Create a new GCM + // Create a new GCM aesGCM, err := cipher.NewGCM(block) if err != nil { return "", err } - //Get the nonce size + // Get the nonce size nonceSize := aesGCM.NonceSize() - //Extract the nonce from the encrypted data + // Extract the nonce from the encrypted data nonce, cipherBuf := enc[:nonceSize], enc[nonceSize:] - //Decrypt the data + // Decrypt the data plainBuf, err := aesGCM.Open(nil, nonce, cipherBuf, nil) if err != nil { return "", err