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

google / webcrypto.dart / 25232696112

01 May 2026 08:53PM UTC coverage: 90.337% (-0.1%) from 90.474%
25232696112

push

github

web-flow
ci: trim browser matrix and cache Android AVD (#266)

3730 of 4129 relevant lines covered (90.34%)

1.31 hits per line

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

72.22
/lib/src/testing/webcrypto/pbkdf2.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:typed_data';
16

17
import 'package:webcrypto/webcrypto.dart';
18
import '../utils/utils.dart';
19
import '../utils/testrunner.dart';
20

21
/// Utility to hold both [Pbkdf2SecretKey] and [rawKeyData], such that we can
22
/// fake an implementation of `exportPrivaterawKey` for [TestRunner].
23
class _ExportablePbkdf2SecretKey {
24
  final Pbkdf2SecretKey pbkdf2SecretKey;
25
  final List<int> rawKeyData;
26
  _ExportablePbkdf2SecretKey(this.pbkdf2SecretKey, this.rawKeyData);
1✔
27
}
28

29
final runner = TestRunner.symmetric<_ExportablePbkdf2SecretKey>(
3✔
30
  algorithm: 'PBKDF2',
31
  importPrivateRawKey: (keyData, keyImportParams) async {
1✔
32
    return _ExportablePbkdf2SecretKey(
1✔
33
      await Pbkdf2SecretKey.importRawKey(keyData),
1✔
34
      keyData,
35
    );
36
  },
37
  // Not really support by [Pbkdf2SecretKey] but required by [TestRunner].
38
  exportPrivateRawKey: (key) async => key.rawKeyData,
2✔
39
  importPrivatePkcs8Key: null, // not supported
40
  exportPrivatePkcs8Key: null,
41
  importPrivateJsonWebKey: null,
42
  exportPrivateJsonWebKey: null,
43
  generateKey: (generateKeyPairParams) async {
×
44
    final rawKeyData = Uint8List(generateKeyPairParams['length']);
×
45
    fillRandomBytes(rawKeyData);
×
46
    return _ExportablePbkdf2SecretKey(
×
47
      await Pbkdf2SecretKey.importRawKey(rawKeyData),
×
48
      rawKeyData,
49
    );
50
  },
51
  deriveBits: (key, length, deriveParams) => key.pbkdf2SecretKey.deriveBits(
3✔
52
    length,
53
    hashFromJson(deriveParams),
1✔
54
    bytesFromJson(deriveParams, 'salt')!,
1✔
55
    deriveParams['iterations'],
1✔
56
  ),
57
  testData: _testData,
1✔
58
);
59

60
void main() async {
×
61
  log('generate Pbkdf2SecretKey test case');
×
62
  await runner.generate(
×
63
    generateKeyParams: {'length': 91},
×
64
    importKeyParams: {},
×
65
    deriveParams: {
×
66
      'hash': hashToJson(Hash.sha256),
×
67
      'salt': bytesToJson(List.generate(42, (i) => (i + i) % 256)),
×
68
      'iterations': 2000,
69
    },
70
    minDeriveLength: 256,
71
    maxDeriveLength: 256,
72
  );
73
  log('--------------------');
×
74

75
  await runner.tests().runTests();
×
76
}
77

78
// TODO: Augments tests with test vectors from: https://www.rfc-editor.org/rfc/rfc6070
79

80
// Allow single quotes for hardcoded testData written as JSON:
81
// ignore_for_file: prefer_single_quotes
82
final _testData = [
3✔
83
  {
1✔
84
    "name": "SHA-384/2/512 generated on boringssl/linux at 2020-01-26T20:46:06",
85
    "privateRawKeyData": "kxoGkUuBRbVcRFx6TmdwN952GvTCwYxBoPkPdhTdZw==",
86
    "derivedBits":
87
        "p6koJ5irMF5b7HqfsYPG/RCqFTC2jApFGn9EUkYVRzSI/8eAHg8mVZ/L6AG8JB2c5Vi6WLXS6A4ZG05wTGZQjw==",
88
    "derivedLength": 512,
89
    "importKeyParams": {},
1✔
90
    "deriveParams": {
1✔
91
      "hash": "sha-384",
92
      "salt": "AAIEBggKDA4QEhQWGBocHiA=",
93
      "iterations": 2,
94
    },
95
  },
96
  {
1✔
97
    "name": "SHA-384/2/512 generated on chrome/linux at 2020-01-26T20:46:17",
98
    "privateRawKeyData": "MzZMAfbcm45AcEFWCCp463xBXfsM3kUGbfwvHbwZGA==",
99
    "derivedBits":
100
        "OgAQ5edJsYjLrp33lhp1PLObJ8EEyE10xU/BwNvv88DFFE/5eFEZZ4sCoywz7U/pib85M5C/S822YqWCqWcNhg==",
101
    "derivedLength": 512,
102
    "importKeyParams": {},
1✔
103
    "deriveParams": {
1✔
104
      "hash": "sha-384",
105
      "salt": "AAIEBggKDA4QEhQWGBocHiA=",
106
      "iterations": 2,
107
    },
108
  },
109
  {
1✔
110
    "name": "SHA-384/2/512 generated on firefox/linux at 2020-01-26T20:46:22",
111
    "privateRawKeyData": "lvpsUi3gpPiyRqBAKRZHgXqyyiAFi1qEi5c0iWqpBw==",
112
    "derivedBits":
113
        "A3d1xewG2vpDCPGUwtUD0vnxvAttR5ooe1oo07Tn2kRwEGr8oY2UT0fCoKdT4zDgNQuGPYTJ2dAX1s7nFjMxCw==",
114
    "derivedLength": 512,
115
    "importKeyParams": {},
1✔
116
    "deriveParams": {
1✔
117
      "hash": "sha-384",
118
      "salt": "AAIEBggKDA4QEhQWGBocHiA=",
119
      "iterations": 2,
120
    },
121
  },
122
  {
1✔
123
    "name":
124
        "SHA-256/200/2048 generated on boringssl/linux at 2020-01-26T20:51:19",
125
    "privateRawKeyData": "yyMsKhVOxc9PHza86irjtXRi8UALVNFG",
126
    "derivedBits":
127
        "X8ErmooBkBYk+OtYy4KheRfqUMgTo8r9ZhxN/A5jpcMJ3LPRLrwBLLo12gFlfp/O9G68pGaqM5+dZ1AseHxCDRU9cUh5PHtP8VoihXT4+xjLroAS2C8QaXAdn7gpfSwZhORmUPIeilWtfp2ylD9qpChrCw3uIN23pfDQyGL516API+HEguWuk0JRBZQqAhtuuLN2fWjXXtEFTXBaeKqdKxguog9FNzjfjvBXc9hdbbBkr7e49nlV67SB+EbzbcV0sPL76cIXYW/97BdYcmR9wYHaFHZy0PQt0p0YglVtS1XzVYTX+qpi76gZvRV199NQTotQ0F0Lv3qljak/Am4Bjg==",
128
    "derivedLength": 2048,
129
    "importKeyParams": {},
1✔
130
    "deriveParams": {
1✔
131
      "hash": "sha-256",
132
      "salt":
133
          "AAIEBggKDA4QEhQWGBocHiAiJCYoKiwuMDI0Njg6PD5AQkRGSEpMTlBSVFZYWlxeYGJkZmhqbG5wcnR2eHp8foCChA==",
134
      "iterations": 200,
135
    },
136
  },
137
  {
1✔
138
    "name": "SHA-256/200/2048 generated on chrome/linux at 2020-01-26T20:51:28",
139
    "privateRawKeyData": "3CRm+aqhHKKVOkjwxO5a39u+4dLh+bZU",
140
    "derivedBits":
141
        "xkxmTIGP23MjiztNyiit1+2SDoQtx/FAhXBPaeFUW55gI2rtJ4HMjhX8oMH17Ito275PHlEVDayNZ+JEgmlvL/UzRjEjGmkWLEDtlbVkewg7gZruJJOaizTVbYdTXnB4cYePkRhgimVT0yPKzWT5ncC75b8nhmDBw7E1hpcs4JqOtoRrz2+ZduU6sKrbXU9p47JiZVi4utNhn+GtrTIGzSZpadB01M56BOuHNcSWeP8lb1ck/pL7Af0csWRvKwU1YMlCp0HGnwUxzhpMPU7kWE9JsPBK5VdTQD0zKciRu8G6njCdmUECFKnx/+9YcAmLGD6GubnN1q+k5P2iPFoAAg==",
142
    "derivedLength": 2048,
143
    "importKeyParams": {},
1✔
144
    "deriveParams": {
1✔
145
      "hash": "sha-256",
146
      "salt":
147
          "AAIEBggKDA4QEhQWGBocHiAiJCYoKiwuMDI0Njg6PD5AQkRGSEpMTlBSVFZYWlxeYGJkZmhqbG5wcnR2eHp8foCChA==",
148
      "iterations": 200,
149
    },
150
  },
151
  {
1✔
152
    "name":
153
        "SHA-256/200/2048 generated on firefox/linux at 2020-01-26T20:51:34",
154
    "privateRawKeyData": "t2CEEuWQLzK8X4/VdvWSXeM0rs7CqEoZ",
155
    "derivedBits":
156
        "hYwPZLpZLY/85GYy5dmgDFlaAGVDOc6a+185CzHT9lzmbvyr/va0BdetlaKlLp0oDEMFk/T+pbTGiXbO77w72MAZ4Ex5TEEwHS1SbCLBl3eNpww2Hp3GNbR99XytzRJXspTVCHcI4myH77XSroqLHmrcMOBG+hzPPldeGAIot884m+xE1sSQ2tciwr5BGaDYm70vHoRrrA7V/DMLcBVwe0vLXdTYRJ+MJA7m49AcvMNIHuG4IcFH8YjBQJzpBr9AAvoWrjCi2aShL9fiUICciSo/xHWMhwxmd1ey0zQHTR+pRgJvn2cfWQ8j2yvM/2brZZ4DXvLqsMspRsANNeSPYQ==",
157
    "derivedLength": 2048,
158
    "importKeyParams": {},
1✔
159
    "deriveParams": {
1✔
160
      "hash": "sha-256",
161
      "salt":
162
          "AAIEBggKDA4QEhQWGBocHiAiJCYoKiwuMDI0Njg6PD5AQkRGSEpMTlBSVFZYWlxeYGJkZmhqbG5wcnR2eHp8foCChA==",
163
      "iterations": 200,
164
    },
165
  },
166
  {
1✔
167
    "name":
168
        "SHA-256/2000/256 generated on boringssl/linux at 2020-01-26T20:53:30",
169
    "privateRawKeyData":
170
        "4XkbSK7qF2Y8VJRFPK9IKwlsaESTJakBb6W4iRzh0tUz0vRK1vPtKpbXUWyYYdVmgIsJyErlj6Bs7fBkk4emxMHiibHBtITzB4cxTv445WFbxZ0z6U1133XKIw==",
171
    "derivedBits": "X6TgJrH/g3gdofA8uXIUNjc3vW/aS+8Ujcl5Hwf2P7k=",
172
    "derivedLength": 256,
173
    "importKeyParams": {},
1✔
174
    "deriveParams": {
1✔
175
      "hash": "sha-256",
176
      "salt": "AAIEBggKDA4QEhQWGBocHiAiJCYoKiwuMDI0Njg6PD5AQkRGSEpMTlBS",
177
      "iterations": 2000,
178
    },
179
  },
180
  {
1✔
181
    "name": "SHA-256/2000/256 generated on chrome/linux at 2020-01-26T20:53:37",
182
    "privateRawKeyData":
183
        "T4mukl1lWjzS31gfkv8+lNOJXS30EKQhgeX6aE4tJkZAC9fxokxRwtNZwf0R94Rm4BkNCsb19w2zV2hZBi9/Eb3CsYpZr3zUOdybqZDxLGlSQcXE2y4jgAb7Dw==",
184
    "derivedBits": "P+pCuZlUMVi0AbTNPPcJK6+vdDzGeufWue6v3lp0v9s=",
185
    "derivedLength": 256,
186
    "importKeyParams": {},
1✔
187
    "deriveParams": {
1✔
188
      "hash": "sha-256",
189
      "salt": "AAIEBggKDA4QEhQWGBocHiAiJCYoKiwuMDI0Njg6PD5AQkRGSEpMTlBS",
190
      "iterations": 2000,
191
    },
192
  },
193
  {
1✔
194
    "name":
195
        "SHA-256/2000/256 generated on firefox/linux at 2020-01-26T20:53:43",
196
    "privateRawKeyData":
197
        "P9W0f/ILv4mv45XGQh5DRy5anxkPqjVa6aPbEIgUvUsVqR0XwKlpCGYDkOuEeCKSemUC39ucWCEs1i/pqIy7mXSCpKvxVFKxCaAglSlBGZrCHD4jbxaGuTdelg==",
198
    "derivedBits": "gWWgqU5qtNl9UFTdGBAYThixXoYDbnxkXbQLSuD4zys=",
199
    "derivedLength": 256,
200
    "importKeyParams": {},
1✔
201
    "deriveParams": {
1✔
202
      "hash": "sha-256",
203
      "salt": "AAIEBggKDA4QEhQWGBocHiAiJCYoKiwuMDI0Njg6PD5AQkRGSEpMTlBS",
204
      "iterations": 2000,
205
    },
206
  },
207
];
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