mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
ext/standard/md5: Minor refactorings (#18518)
- Use size_t type instead of int type - Use false instead of 0 - Remove wrapping comments
This commit is contained in:
parent
e3715cddf0
commit
c6a9beebff
2 changed files with 8 additions and 13 deletions
|
@ -19,32 +19,29 @@
|
|||
#include "php.h"
|
||||
#include "md5.h"
|
||||
|
||||
PHPAPI void make_digest(char *md5str, const unsigned char *digest) /* {{{ */
|
||||
PHPAPI void make_digest(char *md5str, const unsigned char *digest)
|
||||
{
|
||||
make_digest_ex(md5str, digest, 16);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) /* {{{ */
|
||||
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len)
|
||||
{
|
||||
static const char hexits[17] = "0123456789abcdef";
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
md5str[i * 2] = hexits[digest[i] >> 4];
|
||||
md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F];
|
||||
}
|
||||
md5str[len * 2] = '\0';
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Calculate the md5 hash of a string */
|
||||
/* Calculate the md5 hash of a string */
|
||||
PHP_FUNCTION(md5)
|
||||
{
|
||||
zend_string *arg;
|
||||
bool raw_output = 0;
|
||||
PHP_MD5_CTX context;
|
||||
unsigned char digest[16];
|
||||
bool raw_output = false;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 2)
|
||||
Z_PARAM_STR(arg)
|
||||
|
@ -63,14 +60,13 @@ PHP_FUNCTION(md5)
|
|||
}
|
||||
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Calculate the md5 hash of given filename */
|
||||
/* Calculate the md5 hash of given filename */
|
||||
PHP_FUNCTION(md5_file)
|
||||
{
|
||||
char *arg;
|
||||
size_t arg_len;
|
||||
bool raw_output = 0;
|
||||
bool raw_output = false;
|
||||
unsigned char buf[1024];
|
||||
unsigned char digest[16];
|
||||
PHP_MD5_CTX context;
|
||||
|
@ -113,7 +109,6 @@ PHP_FUNCTION(md5_file)
|
|||
make_digest_ex(Z_STRVAL_P(return_value), digest, 16);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security,
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#define MD5_H
|
||||
|
||||
PHPAPI void make_digest(char *md5str, const unsigned char *digest);
|
||||
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len);
|
||||
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len);
|
||||
|
||||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue