OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <ctype.h> // isspace. | 5 #include <ctype.h> // isspace. |
6 | 6 |
7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
8 | 8 |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 seed |= (static_cast<uint64_t>(rnd->NextUInt32()) << 32); | 198 seed |= (static_cast<uint64_t>(rnd->NextUInt32()) << 32); |
199 return CreateRandomState(zone, seed); | 199 return CreateRandomState(zone, seed); |
200 } | 200 } |
201 | 201 |
202 | 202 |
203 DEFINE_NATIVE_ENTRY(SecureRandom_getBytes, 1) { | 203 DEFINE_NATIVE_ENTRY(SecureRandom_getBytes, 1) { |
204 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(0)); | 204 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(0)); |
205 const intptr_t n = count.Value(); | 205 const intptr_t n = count.Value(); |
206 ASSERT((n > 0) && (n <= 8)); | 206 ASSERT((n > 0) && (n <= 8)); |
207 uint8_t buffer[8]; | 207 uint8_t buffer[8]; |
208 Dart_EntropySource entropy_source = isolate->entropy_source_callback(); | 208 Dart_EntropySource entropy_source = Dart::entropy_source_callback(); |
209 if ((entropy_source == NULL) || !entropy_source(buffer, n)) { | 209 if ((entropy_source == NULL) || !entropy_source(buffer, n)) { |
210 const String& error = String::Handle(String::New( | 210 const String& error = String::Handle(String::New( |
211 "No source of cryptographically secure random numbers available.")); | 211 "No source of cryptographically secure random numbers available.")); |
212 const Array& args = Array::Handle(Array::New(1)); | 212 const Array& args = Array::Handle(Array::New(1)); |
213 args.SetAt(0, error); | 213 args.SetAt(0, error); |
214 Exceptions::ThrowByType(Exceptions::kUnsupported, args); | 214 Exceptions::ThrowByType(Exceptions::kUnsupported, args); |
215 } | 215 } |
216 uint64_t result = 0; | 216 uint64_t result = 0; |
217 for (intptr_t i = 0; i < n; i++) { | 217 for (intptr_t i = 0; i < n; i++) { |
218 result = (result << 8) | buffer[i]; | 218 result = (result << 8) | buffer[i]; |
219 } | 219 } |
220 return Integer::New(result); | 220 return Integer::New(result); |
221 } | 221 } |
222 | 222 |
223 } // namespace dart | 223 } // namespace dart |
OLD | NEW |