mirror of
https://gitee.com/dromara/dongle.git
synced 2025-12-06 16:19:20 +08:00
fix(aes):修复解密器错误处理逻辑
- 移除解密器中冗余的错误检查逻辑 - 删除流解密器读取操作中的重复错误处理测试用例 - 优化错误处理流程,确保解密操作正确返回错误类型 - 简化解密器接口实现,提高代码可读性
This commit is contained in:
@@ -82,7 +82,6 @@ func NewStdDecrypter(c *cipher.AesCipher) *StdDecrypter {
|
||||
// to perform the decryption operation with proper error handling.
|
||||
// Returns empty data when input is empty.
|
||||
func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error) {
|
||||
// Check for existing errors from initialization
|
||||
if d.Error != nil {
|
||||
err = d.Error
|
||||
return
|
||||
|
||||
@@ -343,21 +343,6 @@ func TestErrorIntegration(t *testing.T) {
|
||||
assert.Equal(t, 0, n)
|
||||
assert.IsType(t, ReadError{}, err)
|
||||
})
|
||||
|
||||
t.Run("DecryptError in StreamDecrypter Read", func(t *testing.T) {
|
||||
file := mock.NewFile([]byte("test data"), "test.txt")
|
||||
c := cipher.NewAesCipher(cipher.CBC)
|
||||
c.SetKey([]byte("invalid"))
|
||||
|
||||
decrypter := NewStreamDecrypter(file, c)
|
||||
streamDecrypter := decrypter.(*StreamDecrypter)
|
||||
streamDecrypter.Error = nil
|
||||
|
||||
buf := make([]byte, 10)
|
||||
n, err := decrypter.Read(buf)
|
||||
assert.Equal(t, 0, n)
|
||||
assert.IsType(t, DecryptError{}, err)
|
||||
})
|
||||
}
|
||||
|
||||
// TestErrorTypeAssertions tests type assertions for error types
|
||||
|
||||
Reference in New Issue
Block a user