Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
bin
crypto.cc
Go to the documentation of this 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
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
namespace
dart
{
11
namespace
bin {
12
13
void
FUNCTION_NAME
(
Crypto_GetRandomBytes
)(
Dart_NativeArguments
args
) {
14
Dart_Handle
count_obj =
Dart_GetNativeArgument
(
args
, 0);
15
const
int64_t kMaxRandomBytes = 4096;
16
int64_t count64 = 0;
17
if
(!
DartUtils::GetInt64Value
(count_obj, &count64) || (count64 < 0) ||
18
(count64 > kMaxRandomBytes)) {
19
Dart_Handle
error
=
DartUtils::NewString
(
20
"Invalid argument: count must be a positive int "
21
"less than or equal to 4096."
);
22
Dart_ThrowException
(
error
);
23
}
24
intptr_t
count
=
static_cast<
intptr_t
>
(count64);
25
uint8_t*
buffer
=
Dart_ScopeAllocate
(
count
);
26
ASSERT
(
buffer
!=
nullptr
);
27
if
(!
Crypto::GetRandomBytes
(
count
,
buffer
)) {
28
Dart_ThrowException
(
DartUtils::NewDartOSError
());
29
UNREACHABLE
();
30
}
31
Dart_Handle
result
=
Dart_NewTypedData
(
Dart_TypedData_kUint8
,
count
);
32
if
(
Dart_IsError
(
result
)) {
33
Dart_Handle
error
=
DartUtils::NewString
(
"Failed to allocate storage."
);
34
Dart_ThrowException
(
error
);
35
UNREACHABLE
();
36
}
37
Dart_ListSetAsBytes
(
result
, 0,
buffer
,
count
);
38
Dart_SetReturnValue
(
args
,
result
);
39
}
40
41
}
// namespace bin
42
}
// namespace dart
count
int count
Definition
FontMgrTest.cpp:50
UNREACHABLE
#define UNREACHABLE()
Definition
assert.h:248
FUNCTION_NAME
#define FUNCTION_NAME(name)
Definition
builtin.h:19
dart::bin::Crypto::GetRandomBytes
static bool GetRandomBytes(intptr_t count, uint8_t *buffer)
dart::bin::DartUtils::NewDartOSError
static Dart_Handle NewDartOSError()
Definition
dartutils.cc:706
dart::bin::DartUtils::GetInt64Value
static bool GetInt64Value(Dart_Handle value_obj, int64_t *value)
Definition
dartutils.cc:116
dart::bin::DartUtils::NewString
static Dart_Handle NewString(const char *str)
Definition
dartutils.h:214
crypto.h
dart_api.h
Dart_Handle
struct _Dart_Handle * Dart_Handle
Definition
dart_api.h:258
Dart_NativeArguments
struct _Dart_NativeArguments * Dart_NativeArguments
Definition
dart_api.h:3010
Dart_TypedData_kUint8
@ Dart_TypedData_kUint8
Definition
dart_api.h:2606
dartutils.h
ASSERT
#define ASSERT(E)
Definition
entrypoints_verification_test.cc:25
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition
fl_event_channel.h:89
buffer
static const uint8_t buffer[]
Definition
fl_pixel_buffer_texture_test.cc:44
error
const uint8_t uint32_t uint32_t GError ** error
Definition
fl_pixel_buffer_texture_test.cc:40
result
GAsyncResult * result
Definition
fl_text_input_plugin.cc:106
dart::bin::Crypto_GetRandomBytes
void FUNCTION_NAME() Crypto_GetRandomBytes(Dart_NativeArguments args)
Definition
crypto.cc:13
dart
Definition
dart_vm.cc:33
dart::Dart_NewTypedData
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
Definition
dart_api_impl.cc:3799
dart::Dart_ScopeAllocate
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
Definition
dart_api_impl.cc:2199
dart::Dart_SetReturnValue
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
Definition
dart_api_impl.cc:5221
dart::Dart_IsError
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
Definition
dart_api_impl.cc:744
dart::Dart_ListSetAsBytes
DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, intptr_t offset, const uint8_t *native_array, intptr_t length)
Definition
dart_api_impl.cc:3491
dart::Dart_GetNativeArgument
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
Definition
dart_api_impl.cc:5101
dart::Dart_ThrowException
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
Definition
dart_api_impl.cc:4822
Generated on Fri Apr 26 2024 06:14:40 for Flutter Engine by
1.9.8