@@ -52,6 +52,17 @@ ZEND_API zend_string *zend_empty_string = NULL;
5252ZEND_API zend_string * zend_one_char_string [256 ];
5353ZEND_API zend_string * * zend_known_strings = NULL ;
5454
55+ /* this is read-only, so it's ok */
56+ ZEND_SET_ALIGNED (16 , static const char zend_hexconvtab_lower [ ]) = "0123456789abcdef" ;
57+
58+ static zend_always_inline void zend_bin2hex_impl (char * out , const unsigned char * in , size_t in_len , const char * hexconvtab )
59+ {
60+ for (size_t i = 0 ; i < in_len ; i ++ ) {
61+ out [i * 2 ] = hexconvtab [in [i ] >> 4 ];
62+ out [i * 2 + 1 ] = hexconvtab [in [i ] & 0x0f ];
63+ }
64+ }
65+
5566ZEND_API zend_ulong ZEND_FASTCALL zend_string_hash_func (zend_string * str )
5667{
5768 return ZSTR_H (str ) = zend_hash_func (ZSTR_VAL (str ), ZSTR_LEN (str ));
@@ -62,6 +73,21 @@ ZEND_API zend_ulong ZEND_FASTCALL zend_hash_func(const char *str, size_t len)
6273 return zend_inline_hash_func (str , len );
6374}
6475
76+ ZEND_API void ZEND_FASTCALL zend_bin2hex (char * out , const unsigned char * in , size_t in_len )
77+ {
78+ zend_bin2hex_impl (out , in , in_len , zend_hexconvtab_lower );
79+ }
80+
81+ ZEND_API zend_string * zend_bin2hex_str (const unsigned char * in , size_t in_len )
82+ {
83+ zend_string * result = zend_string_safe_alloc (in_len , 2 * sizeof (char ), 0 , 0 );
84+
85+ zend_bin2hex (ZSTR_VAL (result ), in , in_len );
86+ ZSTR_VAL (result )[in_len * 2 ] = '\0' ;
87+
88+ return result ;
89+ }
90+
6591static void _str_dtor (zval * zv )
6692{
6793 zend_string * str = Z_STR_P (zv );
0 commit comments