ZVAL_STRINGL please work

This commit is contained in:
Itamar Levy-Or
2021-06-21 11:58:18 -07:00
committed by Justin Boswell
parent 5397cc35bf
commit e0123d4653
8 changed files with 243 additions and 6 deletions
+1 -1
View File
@@ -11,5 +11,5 @@
#include "http.c"
#include "signing.c"
#include "stream.c"
// #include "hash.c"
#include "hash.c"
#include "crc.c"
+13 -1
View File
@@ -121,4 +121,16 @@ function aws_crt_sign_request_aws(int $signable, int $signing_config, object $on
function aws_crt_crc32(string $input, int $prev): int {}
function aws_crt_crc32c(string $input, int $prev): int {}
function aws_crt_crc32c(string $input, int $prev): int {}
function aws_crt_sha1_new(): int {}
function aws_crt_sha256_new(): int {}
function aws_crt_md5_new(): int {}
function aws_crt_hash_update(int $hash, string $buffer): int{}
function aws_crt_hash_digest(int $hash, int $truncate_to, int $length): string {}
function aws_crt_hash_destroy(int $hash): void {}
+35 -1
View File
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 36d4e512f02a12c10689eb9b0941bcd7837fbf1d */
* Stub hash: 271adcfe560a474d149e60d7951a45a93a9259d3 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_last_error, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
@@ -235,6 +235,28 @@ ZEND_END_ARG_INFO()
#define arginfo_aws_crt_crc32c arginfo_aws_crt_crc32
#define arginfo_aws_crt_sha1_new arginfo_aws_crt_last_error
#define arginfo_aws_crt_sha256_new arginfo_aws_crt_last_error
#define arginfo_aws_crt_md5_new arginfo_aws_crt_last_error
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_hash_update, 0, 2, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, hash, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, buffer, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_hash_digest, 0, 3, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, hash, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, truncate_to, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_hash_destroy, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, hash, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_FUNCTION(aws_crt_last_error);
ZEND_FUNCTION(aws_crt_error_name);
ZEND_FUNCTION(aws_crt_error_str);
@@ -294,6 +316,12 @@ ZEND_FUNCTION(aws_crt_signing_result_apply_to_http_request);
ZEND_FUNCTION(aws_crt_sign_request_aws);
ZEND_FUNCTION(aws_crt_crc32);
ZEND_FUNCTION(aws_crt_crc32c);
ZEND_FUNCTION(aws_crt_sha1_new);
ZEND_FUNCTION(aws_crt_sha256_new);
ZEND_FUNCTION(aws_crt_md5_new);
ZEND_FUNCTION(aws_crt_hash_update);
ZEND_FUNCTION(aws_crt_hash_digest);
ZEND_FUNCTION(aws_crt_hash_destroy);
static const zend_function_entry ext_functions[] = {
@@ -356,5 +384,11 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(aws_crt_sign_request_aws, arginfo_aws_crt_sign_request_aws)
ZEND_FE(aws_crt_crc32, arginfo_aws_crt_crc32)
ZEND_FE(aws_crt_crc32c, arginfo_aws_crt_crc32c)
ZEND_FE(aws_crt_sha1_new, arginfo_aws_crt_sha1_new)
ZEND_FE(aws_crt_sha256_new, arginfo_aws_crt_sha256_new)
ZEND_FE(aws_crt_md5_new, arginfo_aws_crt_md5_new)
ZEND_FE(aws_crt_hash_update, arginfo_aws_crt_hash_update)
ZEND_FE(aws_crt_hash_digest, arginfo_aws_crt_hash_digest)
ZEND_FE(aws_crt_hash_destroy, arginfo_aws_crt_hash_destroy)
ZEND_FE_END
};
+58
View File
@@ -0,0 +1,58 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include "php_aws_crt.h"
PHP_FUNCTION(aws_crt_sha1_new) {
aws_crt_hash *hash = aws_crt_sha1_new();
RETURN_LONG((zend_ulong)hash);
}
PHP_FUNCTION(aws_crt_sha256_new) {
aws_crt_hash *hash = aws_crt_sha256_new();
RETURN_LONG((zend_ulong)hash);
}
PHP_FUNCTION(aws_crt_md5_new) {
aws_crt_hash *hash = aws_crt_md5_new();
RETURN_LONG((zend_ulong)hash);
}
PHP_FUNCTION(aws_crt_hash_update) {
zend_ulong php_hash = 0;
const char * buffer = NULL;
size_t len = 0;
aws_php_parse_parameters("ls", &php_hash, &buffer, &len);
aws_crt_hash *hash = (void *) php_hash;
RETURN_LONG((zend_ulong) aws_crt_hash_update(hash, (uint8_t *)buffer, (uint32_t) len));
}
PHP_FUNCTION(aws_crt_hash_digest) {
zend_ulong php_hash = 0;
size_t truncate_to = 0;
size_t length = 0;
aws_php_parse_parameters("lll", &php_hash, &truncate_to, &length);
aws_crt_hash *hash = (void *) php_hash;
if (truncate_to != 0 && length > truncate_to) {
length = truncate_to;
}
uint8_t *output = aws_crt_hash_digest(hash, truncate_to);
size_t len = strlen((const char *)output) + 1;
char arr[len]; // Make sure there's enough space
strcpy(arr, (char *) output);
printf(arr);
zval *php_output = NULL;
ZVAL_STRINGL(php_output, (const char *)output, length);
aws_mem_release(aws_crt_default_allocator(), output);
// copy false, destroy false?
RETURN_ZVAL(php_output, false, false);
}
PHP_FUNCTION(aws_crt_hash_destroy) {
zend_ulong php_hash = 0;
aws_php_parse_parameters("l", &php_hash);
aws_crt_hash *hash = (void *) php_hash;
aws_crt_hash_destroy(hash);
}