Skip to content

Commit b8097dd

Browse files
committed
Ignore tests that are not available for 2.19
1 parent bdc4138 commit b8097dd

5 files changed

Lines changed: 140 additions & 116 deletions

File tree

‎.github/workflows/release-test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
run: dart pub get
7272

7373
- name: Run tests
74-
run: dart test -p ${{ matrix.platform }}
74+
run: dart test -p ${{ matrix.platform }} ${{ matrix.sdk != 'stable' && '-x stable-only' || '' }}
7575

7676
integration:
7777
needs: lint

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
run: dart pub get
8484

8585
- name: Run tests
86-
run: dart test -p ${{ matrix.platform }}
86+
run: dart test -p ${{ matrix.platform }} ${{ matrix.sdk != 'stable' && '-x stable-only' || '' }}
8787

8888
integration:
8989
needs: lint

‎dart_test.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ tags:
1111
on_platform:
1212
vm:
1313
skip: false
14+
# Tests that only run on the stable Dart SDK.
15+
# CI excludes this tag with `-x stable-only` on Dart 2.19.
16+
stable-only: {}

‎test/compare_pc4_test.dart‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright (c) 2026, Sudipto Chandra
2+
// All rights reserved. Check LICENSE file for details.
3+
4+
// ignore_for_file: library_annotations
5+
6+
// The Blowfish and Twofish engines only exist in pointycastle >= 4.0.0, which
7+
// requires Dart SDK 3.2+. On the 2.19 floor pub resolves an older pointycastle
8+
// without these libraries, so this file cannot compile there. The generic
9+
// `stable-only` tag lets CI exclude it (`-x stable-only`) on non-stable SDKs,
10+
// where the file is skipped at the parse phase before it is ever compiled.
11+
@Tags(['vm-only', 'stable-only'])
12+
13+
import 'dart:typed_data' show Uint8List;
14+
15+
import 'package:cipherlib/cipherlib.dart' as my;
16+
import 'package:cipherlib/codecs.dart';
17+
import 'package:hashlib/random.dart';
18+
import 'package:pointycastle/pointycastle.dart' as pc;
19+
import 'package:pointycastle/block/blowfish.dart';
20+
import 'package:pointycastle/block/modes/cbc.dart';
21+
import 'package:pointycastle/block/modes/ecb.dart';
22+
import 'package:pointycastle/block/twofish.dart';
23+
import 'package:pointycastle/stream/ctr.dart';
24+
import 'package:test/test.dart';
25+
26+
void main() {
27+
group('Blowfish', () {
28+
test('pointycastle: ECB encryption', () {
29+
// pointycastle only supports keys of 4 to 56 bytes
30+
for (int k = 4; k <= 56; k += 4) {
31+
var key = randomBytes(k);
32+
for (int j = 8; j < 200; j += 8) {
33+
var text = randomBytes(j);
34+
var result = my.Blowfish.noPadding(key).ecb().encrypt(text);
35+
var instance = ECBBlockCipher(BlowfishEngine());
36+
instance.init(true, pc.KeyParameter(key));
37+
var out = Uint8List(j);
38+
for (int i = 0; i < j; i += 8) {
39+
instance.processBlock(text, i, out, i);
40+
}
41+
expect(toHex(out), equals(toHex(result)),
42+
reason: '[key: $k, size: $j]');
43+
}
44+
}
45+
});
46+
test('pointycastle: CBC encryption', () {
47+
// pointycastle only supports keys of 4 to 56 bytes
48+
for (int k = 4; k <= 56; k += 4) {
49+
var key = randomBytes(k);
50+
for (int j = 8; j < 200; j += 8) {
51+
var text = randomBytes(j);
52+
var iv = randomBytes(8);
53+
var result = my.Blowfish.noPadding(key).cbc(iv).encrypt(text);
54+
var instance = CBCBlockCipher(BlowfishEngine());
55+
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
56+
var out = Uint8List(j);
57+
for (int i = 0; i < j; i += 8) {
58+
instance.processBlock(text, i, out, i);
59+
}
60+
expect(toHex(out), equals(toHex(result)),
61+
reason: '[key: $k, size: $j]');
62+
}
63+
}
64+
});
65+
test('pointycastle: CTR encryption', () {
66+
// pointycastle only supports keys of 4 to 56 bytes
67+
for (int k = 4; k <= 56; k += 4) {
68+
var key = randomBytes(k);
69+
for (int j = 0; j < 200; ++j) {
70+
var text = randomBytes(j);
71+
var iv = randomBytes(8);
72+
var result = my.Blowfish(key).ctr(iv).encrypt(text);
73+
var instance = CTRStreamCipher(BlowfishEngine());
74+
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
75+
var out = instance.process(text);
76+
expect(toHex(out), equals(toHex(result)),
77+
reason: '[key: $k, size: $j]');
78+
}
79+
}
80+
});
81+
});
82+
83+
group('Twofish', () {
84+
test('pointycastle: ECB encryption', () {
85+
for (int k in [16, 24, 32]) {
86+
var key = randomBytes(k);
87+
for (int j = 16; j < 300; j += 16) {
88+
var text = randomBytes(j);
89+
var result = my.Twofish.noPadding(key).ecb().encrypt(text);
90+
var instance = ECBBlockCipher(TwofishEngine());
91+
instance.init(true, pc.KeyParameter(key));
92+
var out = Uint8List(j);
93+
for (int i = 0; i < j; i += 16) {
94+
instance.processBlock(text, i, out, i);
95+
}
96+
expect(toHex(out), equals(toHex(result)),
97+
reason: '[key: $k, size: $j]');
98+
}
99+
}
100+
});
101+
test('pointycastle: CBC encryption', () {
102+
for (int k in [16, 24, 32]) {
103+
var key = randomBytes(k);
104+
for (int j = 16; j < 300; j += 16) {
105+
var text = randomBytes(j);
106+
var iv = randomBytes(16);
107+
var result = my.Twofish.noPadding(key).cbc(iv).encrypt(text);
108+
var instance = CBCBlockCipher(TwofishEngine());
109+
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
110+
var out = Uint8List(j);
111+
for (int i = 0; i < j; i += 16) {
112+
instance.processBlock(text, i, out, i);
113+
}
114+
expect(toHex(out), equals(toHex(result)),
115+
reason: '[key: $k, size: $j]');
116+
}
117+
}
118+
});
119+
test('pointycastle: CTR encryption', () {
120+
for (int k in [16, 24, 32]) {
121+
var key = randomBytes(k);
122+
for (int j = 0; j < 200; ++j) {
123+
var text = randomBytes(j);
124+
var iv = randomBytes(16);
125+
var result = my.Twofish(key).ctr(iv, 128).encrypt(text);
126+
var instance = CTRStreamCipher(TwofishEngine());
127+
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
128+
var out = instance.process(text);
129+
expect(toHex(out), equals(toHex(result)),
130+
reason: '[key: $k, size: $j]');
131+
}
132+
}
133+
});
134+
});
135+
}

‎test/compare_test.dart‎

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ import 'package:cryptography/cryptography.dart' as crypto;
1414
import 'package:hashlib/random.dart';
1515
import 'package:pointycastle/pointycastle.dart' as pc;
1616
import 'package:pointycastle/block/aes.dart';
17-
import 'package:pointycastle/block/blowfish.dart';
18-
import 'package:pointycastle/block/modes/cbc.dart';
1917
import 'package:pointycastle/block/modes/ccm.dart';
20-
import 'package:pointycastle/block/modes/ecb.dart';
21-
import 'package:pointycastle/block/twofish.dart';
22-
import 'package:pointycastle/stream/ctr.dart';
2318
import 'package:test/test.dart';
2419

2520
void main() {
@@ -472,113 +467,4 @@ void main() {
472467
});
473468
});
474469
});
475-
476-
group('Blowfish', () {
477-
test('pointycastle: ECB encryption', () {
478-
// pointycastle only supports keys of 4 to 56 bytes
479-
for (int k = 4; k <= 56; k += 4) {
480-
var key = randomBytes(k);
481-
for (int j = 8; j < 200; j += 8) {
482-
var text = randomBytes(j);
483-
var result = my.Blowfish.noPadding(key).ecb().encrypt(text);
484-
var instance = ECBBlockCipher(BlowfishEngine());
485-
instance.init(true, pc.KeyParameter(key));
486-
var out = Uint8List(j);
487-
for (int i = 0; i < j; i += 8) {
488-
instance.processBlock(text, i, out, i);
489-
}
490-
expect(toHex(out), equals(toHex(result)),
491-
reason: '[key: $k, size: $j]');
492-
}
493-
}
494-
});
495-
test('pointycastle: CBC encryption', () {
496-
// pointycastle only supports keys of 4 to 56 bytes
497-
for (int k = 4; k <= 56; k += 4) {
498-
var key = randomBytes(k);
499-
for (int j = 8; j < 200; j += 8) {
500-
var text = randomBytes(j);
501-
var iv = randomBytes(8);
502-
var result = my.Blowfish.noPadding(key).cbc(iv).encrypt(text);
503-
var instance = CBCBlockCipher(BlowfishEngine());
504-
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
505-
var out = Uint8List(j);
506-
for (int i = 0; i < j; i += 8) {
507-
instance.processBlock(text, i, out, i);
508-
}
509-
expect(toHex(out), equals(toHex(result)),
510-
reason: '[key: $k, size: $j]');
511-
}
512-
}
513-
});
514-
test('pointycastle: CTR encryption', () {
515-
// pointycastle only supports keys of 4 to 56 bytes
516-
for (int k = 4; k <= 56; k += 4) {
517-
var key = randomBytes(k);
518-
for (int j = 0; j < 200; ++j) {
519-
var text = randomBytes(j);
520-
var iv = randomBytes(8);
521-
var result = my.Blowfish(key).ctr(iv).encrypt(text);
522-
var instance = CTRStreamCipher(BlowfishEngine());
523-
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
524-
var out = instance.process(text);
525-
expect(toHex(out), equals(toHex(result)),
526-
reason: '[key: $k, size: $j]');
527-
}
528-
}
529-
});
530-
});
531-
532-
group('Twofish', () {
533-
test('pointycastle: ECB encryption', () {
534-
for (int k in [16, 24, 32]) {
535-
var key = randomBytes(k);
536-
for (int j = 16; j < 300; j += 16) {
537-
var text = randomBytes(j);
538-
var result = my.Twofish.noPadding(key).ecb().encrypt(text);
539-
var instance = ECBBlockCipher(TwofishEngine());
540-
instance.init(true, pc.KeyParameter(key));
541-
var out = Uint8List(j);
542-
for (int i = 0; i < j; i += 16) {
543-
instance.processBlock(text, i, out, i);
544-
}
545-
expect(toHex(out), equals(toHex(result)),
546-
reason: '[key: $k, size: $j]');
547-
}
548-
}
549-
});
550-
test('pointycastle: CBC encryption', () {
551-
for (int k in [16, 24, 32]) {
552-
var key = randomBytes(k);
553-
for (int j = 16; j < 300; j += 16) {
554-
var text = randomBytes(j);
555-
var iv = randomBytes(16);
556-
var result = my.Twofish.noPadding(key).cbc(iv).encrypt(text);
557-
var instance = CBCBlockCipher(TwofishEngine());
558-
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
559-
var out = Uint8List(j);
560-
for (int i = 0; i < j; i += 16) {
561-
instance.processBlock(text, i, out, i);
562-
}
563-
expect(toHex(out), equals(toHex(result)),
564-
reason: '[key: $k, size: $j]');
565-
}
566-
}
567-
});
568-
test('pointycastle: CTR encryption', () {
569-
for (int k in [16, 24, 32]) {
570-
var key = randomBytes(k);
571-
for (int j = 0; j < 200; ++j) {
572-
var text = randomBytes(j);
573-
var iv = randomBytes(16);
574-
var result = my.Twofish(key).ctr(iv, 128).encrypt(text);
575-
var instance = CTRStreamCipher(TwofishEngine());
576-
instance.init(true, pc.ParametersWithIV(pc.KeyParameter(key), iv));
577-
var out = instance.process(text);
578-
expect(toHex(out), equals(toHex(result)),
579-
reason: '[key: $k, size: $j]');
580-
}
581-
}
582-
});
583-
});
584470
}

0 commit comments

Comments
 (0)