From 42d5ae330fcee5def1fcee4e7e98e01688192002 Mon Sep 17 00:00:00 2001 From: gouguoyin <245629560@qq.com> Date: Fri, 22 Nov 2024 15:04:40 +0800 Subject: [PATCH] Remove useless type conversions --- 3des_test.go | 2 +- blowfish_test.go | 12 ++++++------ cipher_test.go | 4 ++-- des_test.go | 12 ++++++------ tea_test.go | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/3des_test.go b/3des_test.go index 2ac1d47..df12686 100644 --- a/3des_test.go +++ b/3des_test.go @@ -150,7 +150,7 @@ func Test3Des_Decrypt_Bytes(t *testing.T) { } for index, test := range tripleDesTests { - e := Decrypt.FromHexBytes([]byte(test.toHex)).By3Des(getCipher(test.mode, test.padding, []byte(tripleDesKey), []byte(tripleDesIV))) + e := Decrypt.FromHexBytes([]byte(test.toHex)).By3Des(getCipher(test.mode, test.padding, tripleDesKey, tripleDesIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_hex_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) diff --git a/blowfish_test.go b/blowfish_test.go index 80eaf96..709c050 100755 --- a/blowfish_test.go +++ b/blowfish_test.go @@ -121,7 +121,7 @@ func TestBlowfish_Decrypt_String(t *testing.T) { func TestBlowfish_Encrypt_Bytes(t *testing.T) { for index, test := range blowfishTests { raw := Decode.FromBytes([]byte(test.toHex)).ByHex().ToBytes() - e := Encrypt.FromBytes([]byte(test.input)).ByBlowfish(getCipher(test.mode, test.padding, []byte(blowfishKey), []byte(blowfishIV))) + e := Encrypt.FromBytes([]byte(test.input)).ByBlowfish(getCipher(test.mode, test.padding, blowfishKey, blowfishIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_raw_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -141,7 +141,7 @@ func TestBlowfish_Encrypt_Bytes(t *testing.T) { func TestBlowfish_Decrypt_Bytes(t *testing.T) { for index, test := range blowfishTests { raw := Decode.FromBytes([]byte(test.toHex)).ByHex().ToBytes() - e := Decrypt.FromRawBytes(raw).ByBlowfish(getCipher(test.mode, test.padding, []byte(blowfishKey), []byte(blowfishIV))) + e := Decrypt.FromRawBytes(raw).ByBlowfish(getCipher(test.mode, test.padding, blowfishKey, blowfishIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_raw_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -150,7 +150,7 @@ func TestBlowfish_Decrypt_Bytes(t *testing.T) { } for index, test := range blowfishTests { - e := Decrypt.FromHexBytes([]byte(test.toHex)).ByBlowfish(getCipher(test.mode, test.padding, []byte(blowfishKey), []byte(blowfishIV))) + e := Decrypt.FromHexBytes([]byte(test.toHex)).ByBlowfish(getCipher(test.mode, test.padding, blowfishKey, blowfishIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_hex_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -159,7 +159,7 @@ func TestBlowfish_Decrypt_Bytes(t *testing.T) { } for index, test := range blowfishTests { - e := Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByBlowfish(getCipher(test.mode, test.padding, []byte(blowfishKey), []byte(blowfishIV))) + e := Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByBlowfish(getCipher(test.mode, test.padding, blowfishKey, blowfishIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_base64_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -203,11 +203,11 @@ func TestBlowfish_Decoding_Error(t *testing.T) { d1 := Decrypt.FromHexString("xxxx").ByBlowfish(getCipher(CTR, Zero, blowfishKey, blowfishIV)) assert.Equal(t, err.ModeError("hex"), d1.Error) - d2 := Decrypt.FromHexBytes([]byte("xxxx")).ByBlowfish(getCipher(CTR, Zero, []byte(blowfishKey), []byte(blowfishIV))) + d2 := Decrypt.FromHexBytes([]byte("xxxx")).ByBlowfish(getCipher(CTR, Zero, blowfishKey, blowfishIV)) assert.Equal(t, err.ModeError("hex"), d2.Error) d3 := Decrypt.FromBase64String("xxxxxx").ByBlowfish(getCipher(CFB, PKCS7, blowfishKey, blowfishIV)) assert.Equal(t, err.ModeError("base64"), d3.Error) - d4 := Decrypt.FromBase64Bytes([]byte("xxxxxx")).ByBlowfish(getCipher(CFB, PKCS7, []byte(blowfishKey), []byte(blowfishIV))) + d4 := Decrypt.FromBase64Bytes([]byte("xxxxxx")).ByBlowfish(getCipher(CFB, PKCS7, blowfishKey, blowfishIV)) assert.Equal(t, err.ModeError("base64"), d4.Error) } diff --git a/cipher_test.go b/cipher_test.go index 577ccf6..d11553e 100755 --- a/cipher_test.go +++ b/cipher_test.go @@ -12,7 +12,7 @@ func TestCipher_Encrypt(t *testing.T) { cipher.SetMode(CBC) cipher.SetPadding(PKCS7) - block, err1 := aes.NewCipher([]byte(aesKey)) + block, err1 := aes.NewCipher(aesKey) assert.Nil(t, err1) dst, err2 := cipher.Encrypt([]byte(""), block) assert.Nil(t, err2) @@ -24,7 +24,7 @@ func TestCipher_Decrypt(t *testing.T) { cipher.SetMode(CBC) cipher.SetPadding(PKCS7) - block, err1 := aes.NewCipher([]byte(aesKey)) + block, err1 := aes.NewCipher(aesKey) assert.Nil(t, err1) dst, err2 := cipher.Decrypt([]byte(""), block) assert.Nil(t, err2) diff --git a/des_test.go b/des_test.go index b51c679..964c42d 100755 --- a/des_test.go +++ b/des_test.go @@ -121,7 +121,7 @@ func TestDes_Decrypt_String(t *testing.T) { func TestDes_Encrypt_Bytes(t *testing.T) { for index, test := range desTests { raw := Decode.FromBytes([]byte(test.toHex)).ByHex().ToBytes() - e := Encrypt.FromBytes([]byte(test.input)).ByDes(getCipher(test.mode, test.padding, []byte(desKey), []byte(desIV))) + e := Encrypt.FromBytes([]byte(test.input)).ByDes(getCipher(test.mode, test.padding, desKey, desIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_raw_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -141,7 +141,7 @@ func TestDes_Encrypt_Bytes(t *testing.T) { func TestDes_Decrypt_Bytes(t *testing.T) { for index, test := range desTests { raw := Decode.FromBytes([]byte(test.toHex)).ByHex().ToBytes() - e := Decrypt.FromRawBytes(raw).ByDes(getCipher(test.mode, test.padding, []byte(desKey), []byte(desIV))) + e := Decrypt.FromRawBytes(raw).ByDes(getCipher(test.mode, test.padding, desKey, desIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_raw_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -150,7 +150,7 @@ func TestDes_Decrypt_Bytes(t *testing.T) { } for index, test := range desTests { - e := Decrypt.FromHexBytes([]byte(test.toHex)).ByDes(getCipher(test.mode, test.padding, []byte(desKey), []byte(desIV))) + e := Decrypt.FromHexBytes([]byte(test.toHex)).ByDes(getCipher(test.mode, test.padding, desKey, desIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_hex_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -159,7 +159,7 @@ func TestDes_Decrypt_Bytes(t *testing.T) { } for index, test := range desTests { - e := Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByDes(getCipher(test.mode, test.padding, []byte(desKey), []byte(desIV))) + e := Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByDes(getCipher(test.mode, test.padding, desKey, desIV)) t.Run(fmt.Sprintf(string(test.mode)+"_"+string(test.padding)+"_base64_test_%d", index), func(t *testing.T) { assert.Nil(t, e.Error) @@ -203,9 +203,9 @@ func TestDes_Src_Error(t *testing.T) { func TestDes_Decoding_Error(t *testing.T) { err := NewDecodeError() - d1 := Decrypt.FromHexBytes([]byte("xxxx")).ByDes(getCipher(CTR, Zero, []byte(desKey), []byte(desIV))) + d1 := Decrypt.FromHexBytes([]byte("xxxx")).ByDes(getCipher(CTR, Zero, desKey, desIV)) assert.Equal(t, err.ModeError("hex"), d1.Error) - d2 := Decrypt.FromBase64Bytes([]byte("xxxxxx")).ByDes(getCipher(CFB, PKCS7, []byte(desKey), []byte(desIV))) + d2 := Decrypt.FromBase64Bytes([]byte("xxxxxx")).ByDes(getCipher(CFB, PKCS7, desKey, desIV)) assert.Equal(t, err.ModeError("base64"), d2.Error) } diff --git a/tea_test.go b/tea_test.go index 56c1f3b..29b91c1 100755 --- a/tea_test.go +++ b/tea_test.go @@ -61,9 +61,9 @@ func TestTea_Decrypt_String(t *testing.T) { func TestTea_Encrypt_Bytes(t *testing.T) { for index, test := range teaTests { - e := Encrypt.FromBytes([]byte(test.input)).ByTea([]byte(test.key), test.rounds) + e := Encrypt.FromBytes([]byte(test.input)).ByTea(test.key, test.rounds) if test.rounds == 0 { - e = Encrypt.FromBytes([]byte(test.input)).ByTea([]byte(test.key)) + e = Encrypt.FromBytes([]byte(test.input)).ByTea(test.key) } assert.Nil(t, e.Error) assert.Equal(t, []byte(test.toHex), e.ToHexBytes(), "Hex test test index is "+strconv.Itoa(index)) @@ -80,9 +80,9 @@ func TestTea_Decrypt_Bytes(t *testing.T) { assert.Nil(t, e1.Error) assert.Equal(t, []byte(test.input), e1.ToBytes(), "Hex test index is "+strconv.Itoa(index)) - e2 := Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByTea([]byte(test.key), test.rounds) + e2 := Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByTea(test.key, test.rounds) if test.rounds == 0 { - e2 = Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByTea([]byte(test.key)) + e2 = Decrypt.FromBase64Bytes([]byte(test.toBase64)).ByTea(test.key) } assert.Nil(t, e2.Error) assert.Equal(t, []byte(test.input), e2.ToBytes(), "base64 test index is "+strconv.Itoa(index))