Files
sdk/runtime/bin/crypto.cc
T
asiva@google.com ebbb7c4134 - Represent strings internally in UTF-16 format, this makes it
compatible with webkit and will allow for easy externalization of
  strings. One byte strings are retained for pure ASCII strings.
  (The language specification was changed recently to reflect this as
   follows "A string is a sequence of UTF-16 code units").
- Remove four byte string class and all references to it.
- Rename some of the string functions in Dart API to make them
  consistent and better describe the underlying functionality
  Dart_NewString => Dart_NewStringFromCString
  Dart_NewString8 => Dart_NewStringFromUTF8
  Dart_NewString16 => Dart_NewStringFromUTF16
  Dart_NewString32 => Dart_NewStringFromUTF32
  Dart_NewExternalString8 => Dart_NewExternalUTF8String
  Dart_NewExternalString16 => Dart_NewExternalUTF16String
  Dart_NewExternalString32 => Dart_NewExternalUTF32String
  Dart_StringGet8 => Dart_StringToUTF8
  Dart_StringGet16 => Dart_StringToUTF16
  Dart_StringToCString => Dart_StringToCString
  Dart_IsString8 => Removed
  Dart_IsString16 -> Removed
  Dart_StringToBytes -> Removed
  Dart_StringGet32 -> Removed
Review URL: https://codereview.chromium.org//11318018

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14357 260f80e4-7a28-3924-810f-c04153c831b5
2012-10-31 17:56:46 +00:00

37 lines
1.2 KiB
C++

// 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 =
DartUtils::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 = DartUtils::NewString("Failed to allocate storage.");
Dart_ThrowException(error);
}
Dart_ListSetAsBytes(result, 0, buffer, count);
Dart_SetReturnValue(args, result);
delete[] buffer;
Dart_ExitScope();
}