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

Side by Side Diff: bin/crypto.cc

Issue 12255018: Add typed data interface to Dart API, this only changes the C++ API as dicussed in a previous email… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 10 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 | « no previous file | bin/io_buffer.cc » ('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 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) { 11 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
12 Dart_EnterScope(); 12 Dart_EnterScope();
13 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0); 13 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
14 int64_t count = 0; 14 int64_t count = 0;
15 if (!DartUtils::GetInt64Value(count_obj, &count)) { 15 if (!DartUtils::GetInt64Value(count_obj, &count)) {
16 Dart_Handle error = 16 Dart_Handle error =
17 DartUtils::NewString("Invalid argument, must be an int."); 17 DartUtils::NewString("Invalid argument, must be an int.");
18 Dart_ThrowException(error); 18 Dart_ThrowException(error);
19 } 19 }
20 uint8_t* buffer = new uint8_t[count]; 20 uint8_t* buffer = new uint8_t[count];
21 ASSERT(buffer != NULL); 21 ASSERT(buffer != NULL);
22 if (!Crypto::GetRandomBytes(count, buffer)) { 22 if (!Crypto::GetRandomBytes(count, buffer)) {
23 delete[] buffer; 23 delete[] buffer;
24 Dart_ThrowException(DartUtils::NewDartOSError()); 24 Dart_ThrowException(DartUtils::NewDartOSError());
25 } 25 }
26 Dart_Handle result = Dart_NewByteArray(count); 26 Dart_Handle result = Dart_NewTypedData(kUint8, count);
27 if (Dart_IsError(result)) { 27 if (Dart_IsError(result)) {
28 delete[] buffer; 28 delete[] buffer;
29 Dart_Handle error = DartUtils::NewString("Failed to allocate storage."); 29 Dart_Handle error = DartUtils::NewString("Failed to allocate storage.");
30 Dart_ThrowException(error); 30 Dart_ThrowException(error);
31 } 31 }
32 Dart_ListSetAsBytes(result, 0, buffer, count); 32 Dart_ListSetAsBytes(result, 0, buffer, count);
33 Dart_SetReturnValue(args, result); 33 Dart_SetReturnValue(args, result);
34 delete[] buffer; 34 delete[] buffer;
35 Dart_ExitScope(); 35 Dart_ExitScope();
36 } 36 }
OLDNEW
« no previous file with comments | « no previous file | bin/io_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698