• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / webcrypto.dart / 20204101061

14 Dec 2025 06:42AM UTC coverage: 90.347% (+0.6%) from 89.794%
20204101061

push

github

web-flow
chore: fix linter issues (#240)

1233 of 1310 new or added lines in 57 files covered. (94.12%)

10 existing lines in 9 files now uncovered.

4923 of 5449 relevant lines covered (90.35%)

2.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.81
/lib/src/testing/utils/utils.dart
1
// Copyright 2020 Google LLC
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 'dart:async';
16
import 'dart:typed_data';
17
import 'dart:convert';
18
import 'package:webcrypto/webcrypto.dart';
19

20
/// Log [value] from tests.
21
// ignore: avoid_print
22
void log(Object value) => print(value);
×
23

24
/// True, if data should be dumped, this is mostly generated test case
25
const _dumpData = bool.fromEnvironment('webcrypto.dump', defaultValue: false);
26
//const _dumpData = true; // manual override
27

28
/// Dump data, if enabled with `dart -D webcrypto.dump=true <file>`.
29
///
30
/// This can also be overwritten by manually tweaking the [_dumpData] variable.
31
void dump(Map data) {
2✔
32
  if (_dumpData) {
33
    final json = const JsonEncoder.withIndent(
34
      '  ',
NEW
35
    ).convert(data).replaceAll('\n', '\n| ');
×
UNCOV
36
    log('| $json');
×
37
  }
38
}
39

40
/// Check if [condition] hold.
41
void check(bool condition, [String message = 'check failed']) {
2✔
42
  if (!condition) {
1✔
43
    throw AssertionError(message);
×
44
  }
45
}
46

47
extension RunTests on List<({String name, Future<void> Function() test})> {
48
  /// Run tests, print to stdout and throw if tests fail.
49
  Future<void> runTests() async {
×
50
    var failed = false;
51
    for (final (:name, :test) in this) {
×
52
      log('TEST: $name');
×
53
      var pass = true;
54
      try {
55
        await test();
×
56
      } catch (e, st) {
57
        log('FAILED: $name\n$e\n$st\n--------------------------------------');
×
58
        pass = false;
59
        failed = true;
60
      }
61
      if (pass) {
62
        log('PASS: $name');
×
63
      }
64
    }
65
    if (failed) {
66
      throw AssertionError('Some tests failed');
×
67
    } else {
68
      log('ALL TEST PASSED');
×
69
    }
70
  }
71
}
72

73
/// Compare if two byte arrays are equal.
74
bool equalBytes(List<int> a, List<int> b) => base64Encode(a) == base64Encode(b);
8✔
75

76
/// Convert [Stream<List<int>>] to [Uint8List].
77
Future<Uint8List> bufferStream(Stream<List<int>> data) async {
3✔
78
  final b = BytesBuilder();
3✔
79
  await for (var chunk in data) {
5✔
80
    b.add(chunk);
3✔
81
  }
82
  return b.takeBytes();
3✔
83
}
1✔
84

85
Hash hashFromJson(dynamic json) {
3✔
86
  if (json is Map) {
3✔
87
    json = json['hash'];
3✔
88
  }
89
  if (json == 'sha-1') {
3✔
90
    return Hash.sha1;
91
  }
92
  if (json == 'sha-256') {
3✔
93
    return Hash.sha256;
1✔
94
  }
95
  if (json == 'sha-384') {
3✔
96
    return Hash.sha384;
1✔
97
  }
98
  if (json == 'sha-512') {
3✔
99
    return Hash.sha512;
1✔
100
  }
101
  throw AssertionError('invalid hash specification');
×
102
}
1✔
103

104
String hashToJson(Hash h) {
×
105
  if (h == Hash.sha1) {
×
106
    return 'sha-1';
107
  }
108
  if (h == Hash.sha256) {
×
109
    return 'sha-256';
110
  }
111
  if (h == Hash.sha384) {
×
112
    return 'sha-384';
113
  }
114
  if (h == Hash.sha512) {
×
115
    return 'sha-512';
116
  }
117
  throw AssertionError('invalid hash implementation');
×
118
}
119

120
String curveToJson(EllipticCurve curve) {
×
121
  if (curve == EllipticCurve.p256) {
×
122
    return 'p-256';
123
  }
124
  if (curve == EllipticCurve.p384) {
×
125
    return 'p-384';
126
  }
127
  if (curve == EllipticCurve.p521) {
×
128
    return 'p-521';
129
  }
130
  throw AssertionError('invalid curve implementation');
×
131
}
132

133
EllipticCurve curveFromJson(dynamic json) {
3✔
134
  if (json is Map) {
3✔
135
    json = json['curve'];
3✔
136
  }
137
  if (json == 'p-256') {
3✔
138
    return EllipticCurve.p256;
1✔
139
  }
140
  if (json == 'p-384') {
3✔
141
    return EllipticCurve.p384;
142
  }
143
  if (json == 'p-521') {
3✔
144
    return EllipticCurve.p521;
1✔
145
  }
146
  throw AssertionError('invalid curve specification');
×
147
}
1✔
148

149
List<int>? bytesFromJson(Map<String, dynamic> json, String key) {
3✔
150
  if (json[key] != null) {
3✔
151
    return base64Decode(json[key]);
5✔
152
  }
153
  return null;
1✔
154
}
1✔
155

156
String? bytesToJson(List<int>? bytes) {
×
157
  if (bytes != null) {
158
    return base64Encode(bytes);
×
159
  }
160
  return null;
161
}
162

163
/// Flip the first bit of every byte
164
///
165
/// Useful for generating an invalidate signature.
166
Uint8List flipFirstBits(List<int> data) =>
3✔
167
    Uint8List.fromList(data.map((i) => i ^ 0x1).toList());
11✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc