mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-18 10:07:12 +00:00
ZVAL_STRINGL please work
This commit is contained in:
committed by
Justin Boswell
parent
5397cc35bf
commit
e0123d4653
+58
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user