File tree Expand file tree Collapse file tree 13 files changed +94
-74
lines changed Expand file tree Collapse file tree 13 files changed +94
-74
lines changed Original file line number Diff line number Diff line change @@ -112,4 +112,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {
112
112
113
113
@override
114
114
final sha512 = const _Sha512 ();
115
+
116
+ @override
117
+ final random = const _RandomImpl ();
115
118
}
Original file line number Diff line number Diff line change 14
14
15
15
part of 'impl_ffi.dart' ;
16
16
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 ();
23
19
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
+ }
28
33
}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ part 'impl_interface.hkdf.dart';
31
31
part 'impl_interface.rsapss.dart' ;
32
32
part 'impl_interface.rsassapkcs1v15.dart' ;
33
33
part 'impl_interface.digest.dart' ;
34
+ part 'impl_interface.random.dart' ;
34
35
35
36
/// A key-pair as returned from key generation.
36
37
class KeyPair <S , T > {
@@ -115,4 +116,5 @@ abstract interface class WebCryptoImpl {
115
116
HashImpl get sha256;
116
117
HashImpl get sha384;
117
118
HashImpl get sha512;
119
+ RandomImpl get random;
118
120
}
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 interface class RandomImpl {
18
+ void fillRandomBytes (TypedData destination);
19
+ }
Original file line number Diff line number Diff line change @@ -100,4 +100,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {
100
100
101
101
@override
102
102
final sha512 = const _HashImpl ('SHA-512' );
103
+
104
+ @override
105
+ final random = const _RandomImpl ();
103
106
}
Original file line number Diff line number Diff line change 14
14
15
15
part of 'impl_js.dart' ;
16
16
17
- void fillRandomBytes (TypedData destination) {
18
- try {
19
- subtle.getRandomValues (destination);
20
- } on subtle.JSDomException catch (e) {
21
- throw _translateDomException (e);
22
- } on Error catch (e) {
23
- final errorName = e.toString ();
24
- if (errorName != 'JavaScriptError' ) {
25
- rethrow ;
26
- }
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
+ } on Error catch (e) {
27
+ final errorName = e.toString ();
28
+ if (errorName != 'JavaScriptError' ) {
29
+ rethrow ;
30
+ }
27
31
28
- throw _translateJavaScriptException ();
32
+ throw _translateJavaScriptException ();
33
+ }
29
34
}
30
35
}
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';
30
30
part 'impl_stub.rsapss.dart' ;
31
31
part 'impl_stub.rsassapkcs1v15.dart' ;
32
32
part 'impl_stub.digest.dart' ;
33
+ part 'impl_stub.random.dart' ;
33
34
34
35
const WebCryptoImpl webCryptImpl = _WebCryptoImpl ();
35
36
@@ -95,4 +96,7 @@ final class _WebCryptoImpl implements WebCryptoImpl {
95
96
96
97
@override
97
98
final sha512 = const _HashImpl ();
99
+
100
+ @override
101
+ final random = const _RandomImpl ();
98
102
}
Original file line number Diff line number Diff line change 14
14
15
15
part of 'impl_stub.dart' ;
16
16
17
- class _StaticEcdsaPrivateKeyImpl implements StaticEcdsaPrivateKeyImpl {
17
+ final class _StaticEcdsaPrivateKeyImpl implements StaticEcdsaPrivateKeyImpl {
18
18
const _StaticEcdsaPrivateKeyImpl ();
19
19
20
20
@override
@@ -38,7 +38,7 @@ class _StaticEcdsaPrivateKeyImpl implements StaticEcdsaPrivateKeyImpl {
38
38
throw UnimplementedError ('Not implemented' );
39
39
}
40
40
41
- class _StaticEcdsaPublicKeyImpl implements StaticEcdsaPublicKeyImpl {
41
+ final class _StaticEcdsaPublicKeyImpl implements StaticEcdsaPublicKeyImpl {
42
42
const _StaticEcdsaPublicKeyImpl ();
43
43
44
44
@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