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

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

Issue 11175030: Add sessions to HttpServer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "bin/crypto.h"
6 #include "bin/dartutils.h"
7
8 #include "include/dart_api.h"
9
10
11 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
12 Dart_EnterScope();
13 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
14 int64_t count = 0;
15 if (!DartUtils::GetInt64Value(count_obj, &count)) {
16 Dart_Handle error = Dart_NewString("Invalid argument, must be an int.");
17 Dart_ThrowException(error);
18 }
19 uint8_t* buffer = new uint8_t[count];
Søren Gjesse 2012/10/22 11:13:02 Shouldn't we check for NULL here?
Anders Johnsen 2012/10/22 12:18:57 Done.
20 if (!Crypto::GetRandomBytes(count, buffer)) {
21 delete[] buffer;
22 Dart_Handle error = Dart_NewString("Failed to get random bytes.");
Søren Gjesse 2012/10/22 11:13:02 Maybe this should be an OSError is errno/GetLastEr
Anders Johnsen 2012/10/22 12:18:57 Done.
23 Dart_ThrowException(error);
24 }
25 Dart_Handle result = Dart_NewByteArray(count);
26 if (Dart_IsError(result)) {
27 delete[] buffer;
28 Dart_Handle error = Dart_NewString("Failed to allocate storage.");
29 Dart_ThrowException(error);
30 }
31 Dart_ListSetAsBytes(result, 0, buffer, count);
32 Dart_SetReturnValue(args, result);
33 delete[] buffer;
34 Dart_ExitScope();
35 }
36
OLDNEW
« no previous file with comments | « runtime/bin/crypto.h ('k') | runtime/bin/crypto_linux.cc » ('j') | runtime/bin/http.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698