Skip to content

Commit c41d033

Browse files
committed
Add more tests
1 parent 4ee992e commit c41d033

18 files changed

Lines changed: 70 additions & 23 deletions

test/aead_cipher_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2024, Sudipto Chandra
2+
// All rights reserved. Check LICENSE file for details.
3+
4+
import 'package:cipherlib/cipherlib.dart';
5+
import 'package:test/test.dart';
6+
7+
import 'utils.dart' show randomBytes;
8+
9+
void main() {
10+
group('AEADCipherSink', () {
11+
test(r'$add throws UnimplementedError', () {
12+
final key = randomBytes(32);
13+
final nonce = randomBytes(12);
14+
final sink = ChaCha20Poly1305(key, nonce: nonce).createSink();
15+
expect(
16+
() => sink.$add([1, 2, 3], 0, 3),
17+
throwsA(isA<UnimplementedError>()),
18+
);
19+
});
20+
});
21+
}

test/aes_cbc_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void main() {
2626
expect(AES.pkcs7(key).cbc(iv).padding, Padding.pkcs7);
2727
});
2828
test("accepts null IV", () {
29-
AESInCBCMode(key).encrypt(input);
29+
expect(() => AESInCBCMode(key).encrypt(input), returnsNormally);
3030
});
3131
test("encryptor name is correct", () {
3232
expect(AES.noPadding(key).cbc(iv).encryptor.name,

test/aes_cfb_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void main() {
2626
}
2727
});
2828
test("accepts null IV", () {
29-
AESInCFBMode(key).encrypt(input);
29+
expect(() => AESInCFBMode(key).encrypt(input), returnsNormally);
3030
});
3131
test("encryptor name is correct", () {
3232
expect(AES(key).cfb(iv).encryptor.name, "AES#encrypt/CFB/NoPadding");

test/aes_ctr_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() {
1717
expect(AES(key).ctr(iv).name, "AES/CTR/NoPadding");
1818
});
1919
test("accepts null IV", () {
20-
AESInCTRMode(key).encrypt(input);
20+
expect(() => AESInCTRMode(key).encrypt(input), returnsNormally);
2121
});
2222
test("encryptor and decryptor is the same", () {
2323
var aes = AES(key).ctr(iv);

test/aes_ecb_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void main() {
2525
expect(AES.pkcs7(key).ecb().padding, Padding.pkcs7);
2626
});
2727
test("accepts null IV", () {
28-
AESInECBMode(key).encrypt(input);
28+
expect(() => AESInECBMode(key).encrypt(input), returnsNormally);
2929
});
3030
test("encryptor name is correct", () {
3131
expect(

test/aes_gcm_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() {
1717
expect(AES(key).gcm(iv).name, "AES/GCM/NoPadding");
1818
});
1919
test("accepts null IV", () {
20-
AESInGCMMode(key).encrypt(input);
20+
expect(() => AESInGCMMode(key).encrypt(input), returnsNormally);
2121
});
2222
test("encryptor name is correct", () {
2323
expect(AES(key).gcm(iv).encryptor.name, "AES#encrypt/GCM/NoPadding");

test/aes_ige_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void main() {
2626
expect(AES.pkcs7(key).ige(iv).padding, Padding.pkcs7);
2727
});
2828
test("accepts null IV", () {
29-
AESInIGEMode(key).encrypt(input);
29+
expect(() => AESInIGEMode(key).encrypt(input), returnsNormally);
3030
});
3131
test("encryptor name is correct", () {
3232
expect(AES.noPadding(key).ige(iv).encryptor.name,

test/aes_ofb_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() {
1717
expect(AES(key).ofb(iv).name, "AES/OFB/NoPadding");
1818
});
1919
test("accepts null IV", () {
20-
AESInOFBMode(key).encrypt(input);
20+
expect(() => AESInOFBMode(key).encrypt(input), returnsNormally);
2121
});
2222
test("encryptor and decryptor is the same", () {
2323
var aes = AES(key).ofb(iv);

test/aes_pcbc_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void main() {
2626
expect(AES.pkcs7(key).pcbc(iv).padding, Padding.pkcs7);
2727
});
2828
test("accepts null IV", () {
29-
AESInPCBCMode(key).encrypt(input);
29+
expect(() => AESInPCBCMode(key).encrypt(input), returnsNormally);
3030
});
3131
test("encryptor name is correct", () {
3232
expect(AES.noPadding(key).pcbc(iv).encryptor.name,

test/aes_xts_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() {
1717
expect(AES(key).xts(iv).name, "AES/XTS/NoPadding");
1818
});
1919
test("accepts null IV", () {
20-
AESInXTSMode(key).encrypt(input);
20+
expect(() => AESInXTSMode(key).encrypt(input), returnsNormally);
2121
});
2222
test("encryptor name is correct", () {
2323
expect(AES(key).xts(iv).encryptor.name, "AES#encrypt/XTS/NoPadding");

0 commit comments

Comments
 (0)