mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
Port initial methods from old repository
This commit is contained in:
1 parent
f3d2d2df98
commit
87f0fe0e32
5 files changed
+76
No files matched your search
@@ -1,3 +1,4 @@
|
||||
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
|
||||
@@ -122,6 +122,15 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* gdv_fn_sha256_from_numeric(int64_t context, double value){
|
||||
|
||||
|
||||
}
|
||||
|
||||
char* hash_sha256_from_string(int64_t context, const char* value){
|
||||
|
||||
}
|
||||
|
||||
int32_t gdv_fn_dec_from_string(int64_t context, const char* in, int32_t in_length,
|
||||
int32_t* precision_from_str, int32_t* scale_from_str,
|
||||
int64_t* dec_high_from_str, uint64_t* dec_low_from_str) {
|
||||
|
||||
@@ -48,6 +48,10 @@ bool in_expr_lookup_utf8(int64_t ptr, const char* data, int data_len, bool in_va
|
||||
int gdv_fn_time_with_zone(int* time_fields, const char* zone, int zone_len,
|
||||
int64_t* ret_time);
|
||||
|
||||
char* gdv_fn_sha256_from_numeric(int64_t context, double value);
|
||||
|
||||
char* hash_sha256_from_string(int64_t context, const char* value, int32_t value_length);
|
||||
|
||||
int32_t gdv_fn_dec_from_string(int64_t context, const char* in, int32_t in_length,
|
||||
int32_t* precision_from_str, int32_t* scale_from_str,
|
||||
int64_t* dec_high_from_str, uint64_t* dec_low_from_str);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "hash_utils.h"
|
||||
#include "openssl/evp.h"
|
||||
|
||||
namespace gandiva {
|
||||
char* HashUtils::hash_using_SHA256(const void *message, const size_t message_length) {
|
||||
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
|
||||
|
||||
EVP_DigestInit_ex(md_ctx, EVP_sha256(), nullptr);
|
||||
|
||||
EVP_DigestUpdate(md_ctx, message, message_length);
|
||||
|
||||
int sha256_hash_size = EVP_MD_size(EVP_sha256());
|
||||
|
||||
auto* result = (unsigned char*) OPENSSL_malloc(sha256_hash_size);
|
||||
|
||||
unsigned int result_length;
|
||||
|
||||
EVP_DigestFinal_ex(md_ctx, result, &result_length);
|
||||
|
||||
char* hex_buffer = new char[4];
|
||||
char* result_buffer = new char[65];
|
||||
|
||||
clean_char_array(hex_buffer);
|
||||
clean_char_array(result_buffer);
|
||||
|
||||
for (unsigned int j = 0; j < result_length; j++) {
|
||||
unsigned char hex_number = result[j];
|
||||
sprintf(hex_buffer, "%02x", hex_number);
|
||||
|
||||
strcat(result_buffer, hex_buffer);
|
||||
}
|
||||
|
||||
result_buffer[64] = '\0';
|
||||
|
||||
// free the resources to avoid memory leaks
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
free(hex_buffer);
|
||||
free(result);
|
||||
|
||||
return result_buffer;
|
||||
}
|
||||
|
||||
void HashUtils::clean_char_array(char *buffer) {
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef ARROW_SRC_HASH_UTILS_H_
|
||||
#define ARROW_SRC_HASH_UTILS_H_
|
||||
|
||||
#include "gandiva/visibility.h"
|
||||
|
||||
namespace gandiva {
|
||||
class GANDIVA_EXPORT HashUtils {
|
||||
public:
|
||||
static inline char* hash_using_SHA256(const void* message, const size_t message_length);
|
||||
|
||||
private:
|
||||
static inline void clean_char_array(char *buffer);
|
||||
};
|
||||
};
|
||||
|
||||
#endif //ARROW_SRC_HASH_UTILS_H_
|
||||
Reference in new issue
Block a user