File tree Expand file tree Collapse file tree 13 files changed +86
-71
lines changed
Expand file tree Collapse file tree 13 files changed +86
-71
lines changed Original file line number Diff line number Diff line change @@ -122,4 +122,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {
122122
123123 @override
124124 final sha512 = const _Sha512 ();
125+
126+ @override
127+ final random = const _RandomImpl ();
125128}
Original file line number Diff line number Diff line change 1414
1515part of 'impl_ffi.dart' ;
1616
17- void fillRandomBytes (TypedData destination) {
18- return _Scope .sync ((scope) {
19- final dest = destination.buffer.asUint8List (
20- destination.offsetInBytes,
21- destination.lengthInBytes,
22- );
17+ final class _RandomImpl implements RandomImpl {
18+ const _RandomImpl ();
2319
24- final out = scope< ffi.Uint8 > (dest.length);
25- _checkOp (ssl.RAND_bytes (out, dest.length) == 1 );
26- dest.setAll (0 , out.asTypedList (dest.length));
27- });
20+ @override
21+ void fillRandomBytes (TypedData destination) {
22+ return _Scope .sync ((scope) {
23+ final dest = destination.buffer.asUint8List (
24+ destination.offsetInBytes,
25+ destination.lengthInBytes,
26+ );
27+
28+ final out = scope< ffi.Uint8 > (dest.length);
29+ _checkOp (ssl.RAND_bytes (out, dest.length) == 1 );
30+ dest.setAll (0 , out.asTypedList (dest.length));
31+ });
32+ }
2833}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ part 'impl_interface.hkdf.dart';
2929part 'impl_interface.rsapss.dart' ;
3030part 'impl_interface.rsassapkcs1v15.dart' ;
3131part 'impl_interface.digest.dart' ;
32+ part 'impl_interface.random.dart' ;
3233
3334/// A key-pair as returned from key generation.
3435class KeyPair <S , T > {
@@ -99,4 +100,5 @@ abstract interface class WebCryptoImpl {
99100 HashImpl get sha256;
100101 HashImpl get sha384;
101102 HashImpl get sha512;
103+ RandomImpl get random;
102104}
Original file line number Diff line number Diff line change 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+ part of 'impl_interface.dart' ;
16+
17+ abstract class RandomImpl {
18+ void fillRandomBytes (TypedData destination);
19+ }
Original file line number Diff line number Diff line change @@ -109,4 +109,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {
109109
110110 @override
111111 final sha512 = const _HashImpl ('SHA-512' );
112+
113+ @override
114+ final random = const _RandomImpl ();
112115}
Original file line number Diff line number Diff line change 1414
1515part of 'impl_js.dart' ;
1616
17- void fillRandomBytes (TypedData destination) {
18- try {
19- subtle.getRandomValues (destination);
20- } on subtle.JSDomException catch (e) {
21- throw _translateDomException (e);
17+ final class _RandomImpl implements RandomImpl {
18+ const _RandomImpl ();
19+
20+ @override
21+ void fillRandomBytes (TypedData destination) {
22+ try {
23+ subtle.getRandomValues (destination);
24+ } on subtle.JSDomException catch (e) {
25+ throw _translateDomException (e);
26+ }
2227 }
2328}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ part 'impl_stub.hkdf.dart';
3030part 'impl_stub.rsapss.dart' ;
3131part 'impl_stub.rsassapkcs1v15.dart' ;
3232part 'impl_stub.digest.dart' ;
33+ part 'impl_stub.random.dart' ;
3334
3435const WebCryptoImpl webCryptImpl = _WebCryptoImpl ();
3536
@@ -95,4 +96,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {
9596
9697 @override
9798 final sha512 = const _HashImpl ();
99+
100+ @override
101+ final random = const _RandomImpl ();
98102}
Original file line number Diff line number Diff line change 1414
1515part of 'impl_stub.dart' ;
1616
17- class _StaticEcdsaPrivateKeyImpl implements StaticEcdsaPrivateKeyImpl {
17+ final class _StaticEcdsaPrivateKeyImpl implements StaticEcdsaPrivateKeyImpl {
1818 const _StaticEcdsaPrivateKeyImpl ();
1919
2020 @override
@@ -38,7 +38,7 @@ class _StaticEcdsaPrivateKeyImpl implements StaticEcdsaPrivateKeyImpl {
3838 throw UnimplementedError ('Not implemented' );
3939}
4040
41- class _StaticEcdsaPublicKeyImpl implements StaticEcdsaPublicKeyImpl {
41+ final class _StaticEcdsaPublicKeyImpl implements StaticEcdsaPublicKeyImpl {
4242 const _StaticEcdsaPublicKeyImpl ();
4343
4444 @override
Original file line number Diff line number Diff line change 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+ part of 'impl_stub.dart' ;
16+
17+ final class _RandomImpl implements RandomImpl {
18+ const _RandomImpl ();
19+
20+ @override
21+ void fillRandomBytes (TypedData destination) {
22+ throw UnimplementedError ('Not implemented' );
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments