fix(aes):修复解密器错误处理逻辑

- 移除解密器中冗余的错误检查逻辑
- 删除流解密器读取操作中的重复错误处理测试用例
- 优化错误处理流程,确保解密操作正确返回错误类型
- 简化解密器接口实现,提高代码可读性
This commit is contained in:
gouguoyin
2025-10-31 18:23:42 +08:00
parent 65f6344ac0
commit a4c6bb4ca6
2 changed files with 0 additions and 16 deletions

View File

@@ -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

View File

@@ -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