Skip to content

Commit 1d51dd3

Browse files
committed
Adds a test suite.
1 parent 8951cb0 commit 1d51dd3

26 files changed

+1653
-1
lines changed

cryptography_test/.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# See https://www.dartlang.org/guides/libraries/private-files
2+
3+
# Files and directories created by pub
4+
.dart_tool/
5+
.packages
6+
.pub/
7+
build/
8+
# If you're building an application, you may want to check-in your pubspec.lock
9+
pubspec.lock
10+
11+
# Directory created by dartdoc
12+
# If you don't generate documentation locally you can remove this line.
13+
doc/api/
14+
15+
# Miscellaneous
16+
*.class
17+
*.log
18+
*.pyc
19+
*.swp
20+
.DS_Store
21+
.atom/
22+
.buildlog/
23+
.history
24+
.svn/
25+
26+
# IntelliJ related
27+
*.iml
28+
*.ipr
29+
*.iws
30+
.idea/
31+
32+
# The .vscode folder contains launch configuration and tasks you configure in
33+
# VS Code which you may wish to be included in version control, so this line
34+
# is commented out by default.
35+
.vscode/
36+
37+
# Flutter/Dart/Pub related
38+
**/doc/api/
39+
**/ios/Flutter/.last_build_id
40+
.flutter-plugins
41+
.flutter-plugins-dependencies
42+
.pub-cache/
43+
/build/
44+
45+
# Web related
46+
lib/generated_plugin_registrant.dart
47+
48+
# Symbolication related
49+
app.*.symbols
50+
51+
# Obfuscation related
52+
app.*.map.json
53+
54+
# Android Studio will place build artifacts here
55+
/android/app/debug
56+
/android/app/profile
57+
/android/app/release

cryptography_test/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## 0.1.0
2+
* Initial version

cryptography_test/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Introduction
2+
3+
If you are implementing a cryptographic algorithm that implements interfaces of
4+
[pub.dev/packages/cryptography](https://pub.dev/packages/cryptography), this package helps you test
5+
that:
6+
* Your implementation complies with the API specifications.
7+
* Your implementation doesn't fail any sanity checks.
8+
* Your implementation produces same outputs as some existing implementation (when there is one).
9+
10+
# Usage
11+
In pubspec.yaml:
12+
```yaml
13+
dev_dependencies:
14+
cryptography_test: any
15+
```
16+
17+
In your test file:
18+
```dart
19+
import 'package:cryptography_test/cryptography_test.dart';
20+
import 'package:cryptography_test/cipher.dart';
21+
22+
void main() {
23+
testCipher(
24+
builder: () => MyCipher(),
25+
otherTests: () {
26+
test('test vector', () async {
27+
await expectCipherExample(
28+
clearText: hexToBytes('aa bb cc dd'),
29+
secretKey: hexToBytes('aa bb cc dd'),
30+
nonce: hexToBytes('aa bb cc dd'),
31+
aad: hexToBytes('aa bb cc dd'),
32+
cipherText: hexToBytes('aa bb cc dd'),
33+
mac: hexToBytes('aa bb cc dd'),
34+
);
35+
});
36+
},
37+
);
38+
}
39+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

cryptography_test/dart_test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
platforms: [ vm, chrome ]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2023 Gohilla.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:cryptography/cryptography.dart';
16+
import 'package:test/test.dart';
17+
18+
import '../cipher.dart';
19+
20+
void testAesCbc() {
21+
testCipher<AesCbc>(
22+
builder: () => AesCbc.with128bits(
23+
macAlgorithm: MacAlgorithm.empty,
24+
),
25+
onTestSyncCipher: (a, b) {
26+
expect(a.paddingAlgorithm, b.paddingAlgorithm);
27+
},
28+
);
29+
testCipher<AesCbc>(
30+
builder: () => AesCbc.with128bits(
31+
macAlgorithm: MacAlgorithm.empty,
32+
paddingAlgorithm: PaddingAlgorithm.zero,
33+
),
34+
onTestSyncCipher: (a, b) {
35+
expect(a.paddingAlgorithm, b.paddingAlgorithm);
36+
},
37+
);
38+
testCipher(
39+
builder: () => AesCbc.with128bits(
40+
macAlgorithm: Hmac.sha256(),
41+
),
42+
);
43+
testCipher(
44+
builder: () => AesCbc.with192bits(
45+
macAlgorithm: MacAlgorithm.empty,
46+
),
47+
);
48+
testCipher(
49+
builder: () => AesCbc.with256bits(
50+
macAlgorithm: MacAlgorithm.empty,
51+
),
52+
);
53+
testCipher(
54+
builder: () => AesCbc.with256bits(
55+
macAlgorithm: Hmac.sha256(),
56+
),
57+
);
58+
testCipher(
59+
builder: () => AesCbc.with256bits(
60+
macAlgorithm: Hmac.sha512(),
61+
),
62+
);
63+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2023 Gohilla.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:cryptography/cryptography.dart';
16+
17+
import '../cipher.dart';
18+
19+
void testAesCtr() {
20+
testCipher(
21+
builder: () => AesCtr.with128bits(
22+
macAlgorithm: MacAlgorithm.empty,
23+
),
24+
);
25+
testCipher(
26+
builder: () => AesCtr.with128bits(
27+
macAlgorithm: Hmac.sha256(),
28+
),
29+
);
30+
testCipher(
31+
builder: () => AesCtr.with192bits(
32+
macAlgorithm: MacAlgorithm.empty,
33+
),
34+
);
35+
testCipher(
36+
builder: () => AesCtr.with256bits(
37+
macAlgorithm: MacAlgorithm.empty,
38+
),
39+
);
40+
testCipher(
41+
builder: () => AesCtr.with256bits(
42+
macAlgorithm: Hmac.sha256(),
43+
),
44+
);
45+
testCipher(
46+
builder: () => AesCtr.with256bits(
47+
macAlgorithm: Hmac.sha512(),
48+
),
49+
);
50+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2023 Gohilla.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:cryptography/cryptography.dart';
16+
17+
import '../cipher.dart';
18+
19+
void testAesGcm() {
20+
testCipher(
21+
builder: () => AesGcm.with128bits(),
22+
);
23+
testCipher(
24+
builder: () => AesGcm.with192bits(),
25+
);
26+
testCipher(
27+
builder: () => AesGcm.with256bits(),
28+
);
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023 Gohilla.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:cryptography/cryptography.dart';
16+
17+
import '../hash_algorithm.dart';
18+
19+
void testBlake2b() {
20+
testHashAlgorithm(
21+
builder: () => Blake2b(),
22+
otherTests: () {
23+
// ...
24+
},
25+
);
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023 Gohilla.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:cryptography/cryptography.dart';
16+
17+
import '../hash_algorithm.dart';
18+
19+
void testBlake2s() {
20+
testHashAlgorithm(
21+
builder: () => Blake2s(),
22+
otherTests: () {
23+
// ...
24+
},
25+
);
26+
}

0 commit comments

Comments
 (0)