Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: runtime/bin/crypto.cc

Issue 15689013: - Modify dart_api.h to be a proper C API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/dartutils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "bin/crypto.h" 5 #include "bin/crypto.h"
6 #include "bin/dartutils.h" 6 #include "bin/dartutils.h"
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 10
11 namespace dart { 11 namespace dart {
12 namespace bin { 12 namespace bin {
13 13
14 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) { 14 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
15 Dart_EnterScope(); 15 Dart_EnterScope();
16 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0); 16 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
17 int64_t count = 0; 17 int64_t count = 0;
18 if (!DartUtils::GetInt64Value(count_obj, &count)) { 18 if (!DartUtils::GetInt64Value(count_obj, &count)) {
19 Dart_Handle error = 19 Dart_Handle error =
20 DartUtils::NewString("Invalid argument, must be an int."); 20 DartUtils::NewString("Invalid argument, must be an int.");
21 Dart_ThrowException(error); 21 Dart_ThrowException(error);
22 } 22 }
23 uint8_t* buffer = new uint8_t[count]; 23 uint8_t* buffer = new uint8_t[count];
24 ASSERT(buffer != NULL); 24 ASSERT(buffer != NULL);
25 if (!Crypto::GetRandomBytes(count, buffer)) { 25 if (!Crypto::GetRandomBytes(count, buffer)) {
26 delete[] buffer; 26 delete[] buffer;
27 Dart_ThrowException(DartUtils::NewDartOSError()); 27 Dart_ThrowException(DartUtils::NewDartOSError());
28 } 28 }
29 Dart_Handle result = Dart_NewTypedData(kUint8, count); 29 Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, count);
30 if (Dart_IsError(result)) { 30 if (Dart_IsError(result)) {
31 delete[] buffer; 31 delete[] buffer;
32 Dart_Handle error = DartUtils::NewString("Failed to allocate storage."); 32 Dart_Handle error = DartUtils::NewString("Failed to allocate storage.");
33 Dart_ThrowException(error); 33 Dart_ThrowException(error);
34 } 34 }
35 Dart_ListSetAsBytes(result, 0, buffer, count); 35 Dart_ListSetAsBytes(result, 0, buffer, count);
36 Dart_SetReturnValue(args, result); 36 Dart_SetReturnValue(args, result);
37 delete[] buffer; 37 delete[] buffer;
38 Dart_ExitScope(); 38 Dart_ExitScope();
39 } 39 }
40 40
41 } // namespace bin 41 } // namespace bin
42 } // namespace dart 42 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/dartutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698