本文整理汇总了C++中enif_make_binary函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_make_binary函数的具体用法?C++ enif_make_binary怎么用?C++ enif_make_binary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_make_binary函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: nacl_hash
static ERL_NIF_TERM nacl_hash(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[])
{
ErlNifBinary input;
ErlNifBinary result;
if (!enif_inspect_iolist_as_binary(env, argv[0], &input))
return enif_make_badarg(env);
if (!enif_alloc_binary(crypto_hash_BYTES, &result))
return nacl_error_tuple(env, "alloc_failed");
crypto_hash(result.data, input.data, input.size);
return enif_make_binary(env, &result);
}
开发者ID:chinnurtb,项目名称:erlang-nacl,代码行数:15,代码来源:nacl_nif.c
示例2: norm
ERL_NIF_TERM norm(ErlNifEnv* env, ErlNifBinary in,
UNormalizationMode mode)
{
int32_t ulen;
ErlNifBinary out;
UErrorCode status;
ulen = TO_ULEN(in.size);
do_norm(in, out, ulen, mode, status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
do_norm(in, out, ulen, mode, status);
}
CHECK(env, status);
return enif_make_binary(env, &out);
}
开发者ID:alepharchives,项目名称:i18n,代码行数:15,代码来源:i18n_string.cpp
示例3: nacl_randombytes
static ERL_NIF_TERM nacl_randombytes(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[])
{
unsigned int requested_size;
ErlNifBinary result;
if (!enif_get_uint(env, argv[0], &requested_size))
return enif_make_badarg(env);
if (!enif_alloc_binary(requested_size, &result))
return nacl_error_tuple(env, "alloc_failed");
randombytes(result.data, result.size);
return enif_make_binary(env, &result);
}
开发者ID:chinnurtb,项目名称:erlang-nacl,代码行数:15,代码来源:nacl_nif.c
示例4: _hh_rotate
ERL_NIF_TERM _hh_rotate(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
hh_ctx_t* ctx = NULL;
hh_ctx_t* to = NULL;
ErlNifBinary target;
ErlNifResourceType* ctx_type = get_hh_ctx_type(env);
if (argc != 2 ||
ctx_type == NULL ||
!enif_get_resource(env, argv[0], ctx_type, (void **)&ctx) ||
ctx->data == NULL ||
!enif_get_resource(env, argv[1], ctx_type, (void **)&to) ||
to->data == NULL)
{
return enif_make_badarg(env);
}
hdr_histogram_t* diff_histogram;
int rc = 0;
rc = hdr_alloc(ctx->highest_trackable_value, ctx->significant_figures, &diff_histogram);
if (ENOMEM == rc)
{
return make_error(env, "not_enough_memory");
}
hdr_rotate(ctx->data, to->data, diff_histogram);
int size = 0;
uint8_t* data = NULL;
int success = hdr_encode_uncompressed(diff_histogram, &data, &size);
if (!enif_alloc_binary(size, &target))
{
return make_error(env, "bad_hdr_binary_alloc");
}
target.size = size;
memcpy(target.data, data, size);
free(data);
free(diff_histogram);
if (success != 0)
{
return make_error(env, "bad_hdr_binary");
}
return enif_make_binary(env, &target);
}
开发者ID:HdrHistogram,项目名称:hdr_histogram_erl,代码行数:48,代码来源:hdr_histogram_nif.c
示例5: salt_secretbox
static nif_term_t
salt_secretbox(nif_heap_t *hp, int argc, const nif_term_t argv[])
{
/* salt_secretbox(Plain_text, Nonce, Secret_key) -> Cipher_text. */
nif_bin_t pt;
nif_bin_t nc;
nif_bin_t sk;
nif_bin_t ct;
nif_term_t raw;
nif_term_t sub;
if (argc != 3)
return (BADARG);
/* Unpack arguments ensuring they're suitably typed. */
if (! enif_inspect_iolist_as_binary(hp, argv[0], &pt))
return (BADARG);
if (! enif_inspect_binary(hp, argv[1], &nc))
return (BADARG);
if (! enif_inspect_binary(hp, argv[2], &sk))
return (BADARG);
/* Check constraints on size and zero prefixing. */
if (pt.size < crypto_secretbox_ZEROBYTES || pt.size > SALT_MAX_MESSAGE_SIZE)
return (BADARG);
if (memcmp((const void *)pt.data, &salt_secretbox_zerobytes[0], crypto_secretbox_ZEROBYTES) != 0)
return (BADARG);
if (nc.size != crypto_secretbox_NONCEBYTES)
return (BADARG);
if (sk.size != crypto_secretbox_KEYBYTES)
return (BADARG);
/* Allocate space for cipher text. NB: Passing ENOMEM as BADARG. */
if (! enif_alloc_binary(pt.size, &ct))
return (BADARG);
/* Perform the crypto, strip leading zeros. */
(void)crypto_secretbox(ct.data, pt.data, pt.size, nc.data, sk.data);
raw = enif_make_binary(hp, &ct);
sub = enif_make_sub_binary(hp, raw, crypto_secretbox_BOXZEROBYTES, ct.size - crypto_secretbox_BOXZEROBYTES);
return (sub);
}
开发者ID:AnsonSmith,项目名称:salt,代码行数:48,代码来源:salt_nif.c
示例6: emmap_read
static ERL_NIF_TERM emmap_read(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
mhandle *handle;
unsigned long bytes;
if (enif_get_resource(env, argv[0], MMAP_RESOURCE, (void**)&handle)
&& enif_get_ulong(env, argv[1], &bytes)) {
RW_LOCK;
if (handle->position == handle->len) {
RW_UNLOCK;
return ATOM_EOF;
}
unsigned long new_pos = handle->position + bytes;
if (new_pos > handle->len) { new_pos = handle->len; }
long size = new_pos - handle->position;
long start = handle->position;
handle->position = new_pos;
RW_UNLOCK;
if (handle->direct) {
ERL_NIF_TERM res = enif_make_resource_binary
(env, handle, (void*) (((char*)handle->mem) + start), size);
return enif_make_tuple2(env, ATOM_OK, res);
} else {
ErlNifBinary bin;
// When it is non-direct, we have to allocate the binary
if (!enif_alloc_binary((size_t) size, &bin)) {
return make_error_tuple(env, ENOMEM);
}
memcpy(bin.data, (void*) (((char*)handle->mem) + start), size);
ERL_NIF_TERM res = enif_make_binary(env, &bin);
return enif_make_tuple2(env, ATOM_OK, res);
}
} else {
return enif_make_badarg(env);
}
}
开发者ID:alepharchives,项目名称:emmap,代码行数:48,代码来源:emmap.cpp
示例7: seg
static ERL_NIF_TERM seg(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary bin;
enif_inspect_binary(env, argv[0], &bin);
char *text = (char*) bin.data;
size_t size = bin.size;
rmmseg::Algorithm algo(text, size);
std::vector<ERL_NIF_TERM> terms;
for (rmmseg::Token tok = algo.next_token(); tok.length != 0; tok = algo.next_token()) {
ErlNifBinary binText;
enif_alloc_binary(tok.length, &binText);
memcpy(binText.data, tok.text, tok.length);
terms.push_back(enif_make_binary(env, &binText));
}
return enif_make_list_from_array(env, &terms[0], terms.size());
}
开发者ID:kevinlynx,项目名称:erl-rmmseg,代码行数:16,代码来源:erl-rmmseg.cpp
示例8: blake2_hash
ERL_NIF_TERM blake2_hash(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int bits = 0;
enif_get_int(env, argv[0], &bits);
ErlNifBinary bin, out;
enif_inspect_binary(env, argv[1], &bin);
enif_alloc_binary_compat(env, (size_t)(bits/8), &out);
int r = blake2b((uint8_t *)out.data, (const void *)bin.data, NULL, (bits / 8), bin.size, 0);
if (r == 0) {
return enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_binary(env, &out));
} else {
return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_atom(env, "hash_failure"));
}
}
开发者ID:b,项目名称:blake2,代码行数:16,代码来源:blake2_nifs.c
示例9: salt_sign_open
static nif_term_t
salt_sign_open(nif_heap_t *hp, int argc, const nif_term_t argv[])
{
/* salt_sign_open(Signed_msg, Public_key) -> {ok, Verified_msg} | forged_or_garbled. */
unsigned long long len;
nif_bin_t sm;
nif_bin_t pk;
nif_bin_t pm;
nif_term_t raw;
nif_term_t sub;
nif_term_t tag;
if (argc != 2)
return (BADARG);
/* Unpack arguments ensuring they're suitably typed. */
if (! enif_inspect_iolist_as_binary(hp, argv[0], &sm))
return (BADARG);
if (! enif_inspect_binary(hp, argv[1], &pk))
return (BADARG);
/* Check constraints on size. */
if (sm.size < 1 || sm.size > SALT_MAX_MESSAGE_SIZE)
return (BADARG);
if (pk.size != crypto_sign_PUBLICKEYBYTES)
return (BADARG);
/* Perform the crypto, potentially adjust signed message size. */
if (! enif_alloc_binary(sm.size + crypto_sign_BYTES, &pm))
return (BADARG);
if (crypto_sign_open(pm.data, &len, sm.data, sm.size, pk.data) != 0) {
enif_release_binary(&pm);
return (enif_make_atom(hp, "forged_or_garbled"));
}
raw = enif_make_binary(hp, &pm);
tag = enif_make_atom(hp, "ok");
if (len != sm.size)
sub = enif_make_sub_binary(hp, raw, 0, len);
else
sub = raw;
return (enif_make_tuple2(hp, tag, sub));
}
开发者ID:AnsonSmith,项目名称:salt,代码行数:47,代码来源:salt_nif.c
示例10: make_binary
static ERL_NIF_TERM
make_binary(ErlNifEnv *env, const void *bytes, unsigned int size)
{
ErlNifBinary blob;
ERL_NIF_TERM term;
if(!enif_alloc_binary(size, &blob)) {
/* TODO: fix this */
return make_atom(env, "error");
}
memcpy(blob.data, bytes, size);
term = enif_make_binary(env, &blob);
enif_release_binary(&blob);
return term;
}
开发者ID:alepharchives,项目名称:esqlite,代码行数:17,代码来源:esqlite3_nif.c
示例11: keypair_to_binary
static void keypair_to_binary(brine_task_s *task) {
ErlNifEnv *env = task->env;
brine_keypair_s *keypair = task->options.signature.keys;
ErlNifBinary blob;
ERL_NIF_TERM result;
if (!enif_alloc_binary(BRINE_BLOB_SZ, &blob)) {
result = BRINE_ERROR_NO_MEMORY;
}
else {
brine_serialize_keypair(keypair, blob.data, blob.size);
result = enif_make_tuple2(env, enif_make_copy(env, BRINE_ATOM_OK), enif_make_binary(env, &blob));
enif_release_binary(&blob);
}
enif_release_resource((void *) keypair);
enif_send(NULL, &task->owner, task->env, enif_make_tuple2(env, task->ref, result));
}
开发者ID:monkeygroover,项目名称:brine,代码行数:17,代码来源:brine_nif.c
示例12: geef_commit_tree_id
ERL_NIF_TERM
geef_commit_tree_id(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
const git_oid *id;
geef_object *obj;
ErlNifBinary bin;
if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &obj))
return enif_make_badarg(env);
id = git_commit_tree_id((git_commit *) obj->obj);
if (geef_oid_bin(&bin, id) < 0)
return geef_oom(env);
return enif_make_binary(env, &bin);
}
开发者ID:edescourtis,项目名称:geef,代码行数:17,代码来源:commit.c
示例13: nif_compress
//--
static
ERL_NIF_TERM
nif_compress(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary input;
if(!enif_inspect_iolist_as_binary(env, argv[0], &input))
{
return(enif_make_badarg(env));
}
ErlNifBinary bin;
// [rad] Figure out maximum compression buffer size.
uint32_t compressed_bytes = wfLZ_GetMaxCompressedSize(input.size);
// [rad] Get size of recommended scratchpad.
uint32_t scratchpad_bytes = wfLZ_GetWorkMemSize();
if(!enif_alloc_binary(compressed_bytes, &bin))
{
return(erlang_produce_error(env, "not_enough_memory"));
}
// [rad] Allocate scratchpad buffer.
uint8_t* scratchpad = malloc(scratchpad_bytes);
// [rad] Perform compression.
uint32_t data_comp_size = wfLZ_Compress((const uint8_t* const) input.data, input.size, (uint8_t* const) bin.data, (const uint8_t*) scratchpad, 0);
// [rad] We no longer need scratchpad.
free(scratchpad);
if(!data_comp_size)
{
return(erlang_produce_error(env, "compression_error"));
}
if(!enif_realloc_binary(&bin, data_comp_size))
{
return(erlang_produce_error(env, "not_enough_memory"));
}
return(enif_make_binary(env, &bin));
}
开发者ID:Zabrane,项目名称:wflz-erlang-nif,代码行数:46,代码来源:wlfz_nif.c
示例14: aes_ecb_decrypt
static ERL_NIF_TERM aes_ecb_decrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary in, out, key;
// key must be binary
if(!enif_inspect_binary(env, argv[0], &key)) {
return enif_make_badarg(env);
}
// key size should be 16 byte
if(key.size != 16) {
return enif_make_badarg(env);
}
// cipher must be binary
if(!enif_inspect_binary(env, argv[1], &in)) {
return enif_make_badarg(env);
}
// cipher shoule be 16 byte block
if(in.size % 16) {
return enif_make_badarg(env);
}
unsigned char* decoded = (unsigned char*)malloc(sizeof(unsigned char)*in.size);
struct aes_key_st* decrypt_key = (struct aes_key_st*)malloc(sizeof(AES_KEY));
memset(decrypt_key, 0, sizeof(AES_KEY));
AES_set_decrypt_key((unsigned char*)(key.data), 128, decrypt_key);
int i = 0;
for(i = 0; i < in.size; i += 16) {
AES_decrypt((unsigned char*)&in.data[i], (unsigned char*)&decoded[i], decrypt_key);
}
//Remove padding
unsigned char padding = (unsigned char) decoded[in.size-1];
if(!enif_alloc_binary(in.size - padding, &out)) {
free(decoded);
free(decrypt_key);
return enif_make_badarg(env);
}
strncpy((unsigned char*)out.data, decoded, in.size - padding);
free(decoded);
free(decrypt_key);
return enif_make_binary(env, &out);
}
开发者ID:Asif-Malik1,项目名称:soul,代码行数:45,代码来源:aes_nif.c
示例15: decompress
ERL_NIF_TERM
decompress(task_t *task)
{
size_t len;
bool status;
ERL_NIF_TERM result;
ErlNifBinary bin;
len = -1;
status = snappy::GetUncompressedLength(
reinterpret_cast<const char *>(task->data.data),
task->data.size, &len);
if (!status) {
result = enif_make_tuple2(task->env, atom_error,
enif_make_string(task->env, "Data is not compressed",
ERL_NIF_LATIN1));
goto done;
}
if (!enif_alloc_binary(len, &bin)) {
result = enif_make_tuple2(task->env, atom_error,
enif_make_string(task->env, "Couldn't allocate memory",
ERL_NIF_LATIN1));
goto done;
}
status = snappy::RawUncompress(
reinterpret_cast<const char*>(task->data.data),
task->data.size, reinterpret_cast<char*>(bin.data));
if (!status) {
result = enif_make_tuple2(task->env, atom_error,
enif_make_string(task->env, "Failed to decompress",
ERL_NIF_LATIN1));
goto done;
}
result = enif_make_tuple3(task->env, atom_ok, task->ref,
enif_make_binary(task->env, &bin));
done:
return result;
}
开发者ID:fdmanana,项目名称:esnappy,代码行数:45,代码来源:esnappy_nif.cpp
示例16: salt_reply_bytes
static void
salt_reply_bytes(struct salt_msg *sm, nif_bin_t *bs)
{
nif_heap_t *hp = sm->msg_heap;
nif_term_t tag;
nif_term_t res;
nif_term_t msg;
nif_term_t bb;
/* From_pid ! {Mref, {ok, Bytes}} */
bb = enif_make_binary(hp, bs);
tag = enif_make_atom(hp, "ok");
res = enif_make_tuple2(hp, tag, bb);
msg = enif_make_tuple2(hp, sm->msg_mref, res);
(void)enif_send(NULL, &sm->msg_from, hp, msg);
}
开发者ID:AnsonSmith,项目名称:salt,代码行数:18,代码来源:salt_nif.c
示例17: vert_virStoragePoolGetInfo
ERL_NIF_TERM
vert_virStoragePoolGetInfo(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *sp = NULL;
ErlNifBinary info = {0};
VERT_GET_RESOURCE(0, sp, VERT_RES_STORAGEPOOL);
if (!enif_alloc_binary(sizeof(virStoragePoolInfo), &info))
return error_tuple(env, atom_enomem);
VERTERR(virStoragePoolGetInfo(sp->res, (virStoragePoolInfoPtr)info.data) < 0);
return enif_make_tuple2(env,
atom_ok,
enif_make_binary(env, &info));
}
开发者ID:chinnurtb,项目名称:erlang-libvirt,代码行数:18,代码来源:vert_storagepool.c
示例18: geef_hex_to_raw
static ERL_NIF_TERM
geef_hex_to_raw(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
char sha[MAXBUFLEN];
(void)memset(&sha, '\0', sizeof(sha));
if (enif_get_string(env, argv[0], sha, sizeof(sha), ERL_NIF_LATIN1) < 1)
return enif_make_badarg(env);
git_oid oid;
git_oid_fromstr(&oid, sha);
ErlNifBinary ibin;
enif_alloc_binary(20, &ibin);
memcpy(ibin.data, (&oid)->id, 20);
return enif_make_binary(env, &ibin);
}
开发者ID:greenelephantlabs,项目名称:geef,代码行数:18,代码来源:geef.c
示例19: dirty_nif
static ERL_NIF_TERM dirty_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int n;
char s[10];
ErlNifBinary b;
if (have_dirty_schedulers()) {
assert(ERL_NIF_THR_DIRTY_CPU_SCHEDULER == enif_thread_type()
|| ERL_NIF_THR_DIRTY_IO_SCHEDULER == enif_thread_type());
}
assert(argc == 3);
enif_get_int(env, argv[0], &n);
enif_get_string(env, argv[1], s, sizeof s, ERL_NIF_LATIN1);
enif_inspect_binary(env, argv[2], &b);
return enif_make_tuple3(env,
enif_make_int(env, n),
enif_make_string(env, s, ERL_NIF_LATIN1),
enif_make_binary(env, &b));
}
开发者ID:HansN,项目名称:otp,代码行数:18,代码来源:dirty_nif_SUITE.c
示例20: aes_ecb_encrypt
static ERL_NIF_TERM aes_ecb_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary in, out, key;
unsigned char* to_encode;
// First argument must be a binary key
if(!enif_inspect_binary(env, argv[0], &key)) {
return enif_make_badarg(env);
}
// Key size must be 16 bytes
if(key.size != 16) {
return enif_make_badarg(env);
}
// Second argument must be a binary
if(!enif_inspect_binary(env, argv[1], &in)) {
return enif_make_badarg(env);
}
// Pad with PKCS5Padding
unsigned char padding =(unsigned char) (16 - in.size % 16);
to_encode = (unsigned char*)malloc(sizeof(unsigned char) * in.size + padding);
strncpy(to_encode, (unsigned char*)(in.data), in.size);
int j = 0;
for(j = 0; j < padding; j++) {
to_encode[in.size + j] = padding;
}
// If allocation fails we return badarg because there is no API for general errors.
if(!enif_alloc_binary(in.size + padding, &out)) {
free(to_encode);
return enif_make_badarg(env);
}
//Init the key
struct aes_key_st* encrypt_key = (struct aes_key_st*)malloc(sizeof(AES_KEY));
memset(encrypt_key, 0, sizeof(AES_KEY));
AES_set_encrypt_key((unsigned char*)(key.data), 128, encrypt_key);
//Encode!
int i = 0;
for(i = 0; i < in.size + padding; i += 16) {
AES_encrypt((unsigned char*)&to_encode[i], (unsigned char*)&out.data[i], encrypt_key);
}
free(to_encode);
free(encrypt_key);
return enif_make_binary(env, &out);
}
开发者ID:Asif-Malik1,项目名称:soul,代码行数:44,代码来源:aes_nif.c
注:本文中的enif_make_binary函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论