google / google/webcrypto.dart
bug: native AES-CBC reports invalid IV lengths as ArgumentError instead of OperationError
- Dominant language
- Dart
- Stars
- 116
- Forks
- 110
- Avg merge
- 6d 8h
- Merged PRs (30d)
- 9
Description
## Summary
AES-CBC handles an IV whose length is not 16 bytes differently across backends.
On the native FFI backend, encrypting or decrypting with a 15-byte IV throws `ArgumentError`. In Chrome, the same operation rejects with `OperationError`, which matches Web Crypto’s AES-CBC behavior.
## Reproduction
```dart
final key = await AesCbcSecretKey.generateKey(256);
await key.encryptBytes(const [1], List.filled(15, 0));
```
Observed results:
- Native FFI: `ArgumentError: Invalid argument (iv): must be 16 bytes`
- Chrome: `OperationError: The "iv" has an unexpected length -- must be 16 bytes`
The same mismatch applies to both encryption and decryption, and to IVs shorter or longer than 16 bytes.
## Expected behavior
Invalid AES-CBC IV lengths should consistently produce `OperationError` on all supported backends.
## Proposed fix
Change the native AES-CBC validation to report `OperationError`, and add a cross-backend regression covering 15-byte and 17-byte IVs for encryption and decryption.
Contributor guide
Research direction
Start from the AesCbcSecretKey encryption and decryption paths used in the reproduction, then locate the native FFI validation that raises ArgumentError for IV lengths other than 16 bytes. Add a cross-backend regression for 15-byte and 17-byte IVs during both operations, and confirm every backend reports OperationError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100