• 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

70.24
/lib/src/jsonwebkey.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
// ignore_for_file: non_constant_identifier_names
16

17
/// Interface for the [JsonWebKey dictionary][1].
18
///
19
/// See also list of [registered parameters][2].
20
///
21
/// [1]: https://www.w3.org/TR/WebCryptoAPI/#JsonWebKey-dictionary
22
/// [2]: https://www.iana.org/assignments/jose/jose.xhtml#web-key-parameters
23
final class JsonWebKey {
24
  String? kty;
25
  String? use;
26
  List<String>? key_ops;
27
  String? alg;
28
  bool? ext;
29
  String? crv;
30
  String? x;
31
  String? y;
32
  String? d;
33
  String? n;
34
  String? e;
35
  String? p;
36
  String? q;
37
  String? dp;
38
  String? dq;
39
  String? qi;
40
  List<RsaOtherPrimesInfo>? oth;
41
  String? k;
42

43
  JsonWebKey({
1✔
44
    this.kty,
45
    this.use,
46
    this.key_ops,
47
    this.alg,
48
    this.ext,
49
    this.crv,
50
    this.x,
51
    this.y,
52
    this.d,
53
    this.n,
54
    this.e,
55
    this.p,
56
    this.q,
57
    this.dp,
58
    this.dq,
59
    this.qi,
60
    this.oth,
61
    this.k,
62
  });
63

64
  static JsonWebKey fromJson(Map<String, dynamic> json) {
1✔
65
    const stringKeys = [
66
      'kty',
67
      'use',
68
      'alg',
69
      'crv',
70
      'x',
71
      'y',
72
      'd',
73
      'n',
74
      'e',
75
      'p',
76
      'q',
77
      'dp',
78
      'dq',
79
      'qi',
80
      'k',
81
    ];
82
    for (final k in stringKeys) {
2✔
83
      if (json.containsKey(k) && json[k] is! String) {
3✔
84
        throw FormatException('JWK entry "$k" must be a string', json);
×
85
      }
86
    }
87
    List<String>? key_ops;
88
    if (json.containsKey('key_ops')) {
1✔
89
      if (json['key_ops'] is! List ||
×
90
          (json['key_ops'] as List).any((e) => e is! String)) {
×
91
        throw FormatException(
×
92
          'JWK entry "key_ops" must be a list of strings',
93
          json,
94
        );
95
      }
96
      key_ops = (json['key_ops'] as List).map((e) => e as String).toList();
×
97
    }
98

99
    if (json.containsKey('ext') && json['ext'] is! bool) {
1✔
100
      throw FormatException('JWK entry "ext" must be boolean', json);
×
101
    }
102
    List<RsaOtherPrimesInfo>? oth;
103
    if (json.containsKey('oth')) {
1✔
104
      if (json['oth'] is! List || (json['oth'] as List).any((e) => e is! Map)) {
×
105
        throw FormatException('JWK entry "oth" must be list of maps', json);
×
106
      }
107
      oth = (json['oth'] as List<Map>).map((json) {
×
108
        return RsaOtherPrimesInfo.fromJson(json);
×
109
      }).toList();
×
110
    }
111
    return JsonWebKey(
1✔
112
      kty: json['kty'] as String?,
1✔
113
      use: json['use'] as String?,
1✔
114
      key_ops: key_ops,
115
      alg: json['alg'] as String?,
1✔
116
      ext: json['ext'] as bool?,
1✔
117
      crv: json['crv'] as String?,
1✔
118
      x: json['x'] as String?,
1✔
119
      y: json['y'] as String?,
1✔
120
      d: json['d'] as String?,
1✔
121
      n: json['n'] as String?,
1✔
122
      e: json['e'] as String?,
1✔
123
      p: json['p'] as String?,
1✔
124
      q: json['q'] as String?,
1✔
125
      dp: json['dp'] as String?,
1✔
126
      dq: json['dq'] as String?,
1✔
127
      qi: json['qi'] as String?,
1✔
128
      oth: oth,
129
      k: json['k'] as String?,
1✔
130
    );
131
  }
132

133
  Map<String, Object> toJson() {
1✔
134
    final json = <String, Object>{};
1✔
135

136
    // Set properties from all the string keys
137
    final kty_ = kty;
1✔
138
    if (kty_ != null) {
139
      json['kty'] = kty_;
1✔
140
    }
141
    final use_ = use;
1✔
142
    if (use_ != null) {
143
      json['use'] = use_;
1✔
144
    }
145
    final alg_ = alg;
1✔
146
    if (alg_ != null) {
147
      json['alg'] = alg_;
1✔
148
    }
149
    final crv_ = crv;
1✔
150
    if (crv_ != null) {
151
      json['crv'] = crv_;
1✔
152
    }
153
    final x_ = x;
1✔
154
    if (x_ != null) {
155
      json['x'] = x_;
1✔
156
    }
157
    final y_ = y;
1✔
158
    if (y_ != null) {
159
      json['y'] = y_;
1✔
160
    }
161
    final d_ = d;
1✔
162
    if (d_ != null) {
163
      json['d'] = d_;
1✔
164
    }
165
    final n_ = n;
1✔
166
    if (n_ != null) {
167
      json['n'] = n_;
1✔
168
    }
169
    final e_ = e;
1✔
170
    if (e_ != null) {
171
      json['e'] = e_;
1✔
172
    }
173
    final p_ = p;
1✔
174
    if (p_ != null) {
175
      json['p'] = p_;
1✔
176
    }
177
    final q_ = q;
1✔
178
    if (q_ != null) {
179
      json['q'] = q_;
1✔
180
    }
181
    final dp_ = dp;
1✔
182
    if (dp_ != null) {
183
      json['dp'] = dp_;
1✔
184
    }
185
    final dq_ = dq;
1✔
186
    if (dq_ != null) {
187
      json['dq'] = dq_;
1✔
188
    }
189
    final qi_ = qi;
1✔
190
    if (qi_ != null) {
191
      json['qi'] = qi_;
1✔
192
    }
193
    final k_ = k;
1✔
194
    if (k_ != null) {
195
      json['k'] = k_;
1✔
196
    }
197

198
    // Set non-string properties
199
    final key_ops_ = key_ops;
1✔
200
    if (key_ops_ != null) {
201
      json['key_ops'] = key_ops_;
×
202
    }
203
    final ext_ = ext;
1✔
204
    if (ext_ != null) {
205
      json['ext'] = ext_;
×
206
    }
207
    final oth_ = oth;
1✔
208
    if (oth_ != null) {
209
      json['oth'] = oth_.map((e) => e.toJson()).toList();
×
210
    }
211

212
    return json;
213
  }
214
}
215

216
/// Interface for `RsaOtherPrimesInfo` used in the [JsonWebKey dictionary][1].
217
///
218
/// See also "oth" in [RFC 7518 Section 6.3.2.7].
219
///
220
/// [1]: https://www.w3.org/TR/WebCryptoAPI/#JsonWebKey-dictionary
221
/// [2]: https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.7
222
final class RsaOtherPrimesInfo {
223
  String r;
224
  String d;
225
  String t;
226

227
  RsaOtherPrimesInfo({required this.r, required this.d, required this.t});
×
228

229
  static RsaOtherPrimesInfo fromJson(Map json) {
×
230
    for (final k in ['r', 'd', 't']) {
×
231
      if (json[k] is! String) {
×
232
        throw FormatException('"oth" entries in a JWK must contain "$k"', json);
×
233
      }
234
    }
235
    return RsaOtherPrimesInfo(
×
236
      r: json['r'] as String,
×
237
      d: json['d'] as String,
×
238
      t: json['t'] as String,
×
239
    );
240
  }
241

242
  Map<String, Object> toJson() {
×
243
    return <String, Object>{'r': r, 'd': d, 't': t};
×
244
  }
245
}
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