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

Unified 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: Review update. 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/crypto.cc
diff --git a/runtime/bin/crypto.cc b/runtime/bin/crypto.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97984a202a7aefe8a95fc19c0f83007899921c45
--- /dev/null
+++ b/runtime/bin/crypto.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "bin/crypto.h"
+#include "bin/dartutils.h"
+
+#include "include/dart_api.h"
+
+
+void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
+ Dart_EnterScope();
+ Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
+ int64_t count = 0;
+ if (!DartUtils::GetInt64Value(count_obj, &count)) {
+ Dart_Handle error = Dart_NewString("Invalid argument, must be an int.");
+ Dart_ThrowException(error);
+ }
+ uint8_t* buffer = new uint8_t[count];
+ ASSERT(buffer != NULL);
+ if (!Crypto::GetRandomBytes(count, buffer)) {
+ delete[] buffer;
+ Dart_ThrowException(DartUtils::NewDartOSError());
+ }
+ Dart_Handle result = Dart_NewByteArray(count);
+ if (Dart_IsError(result)) {
+ delete[] buffer;
+ Dart_Handle error = Dart_NewString("Failed to allocate storage.");
+ Dart_ThrowException(error);
+ }
+ Dart_ListSetAsBytes(result, 0, buffer, count);
+ Dart_SetReturnValue(args, result);
+ delete[] buffer;
+ Dart_ExitScope();
+}
+
« no previous file with comments | « runtime/bin/crypto.h ('k') | runtime/bin/crypto_linux.cc » ('j') | runtime/bin/http_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698