Convert character array `str` of length `len` to hexadecimal.
| 5855 | |
| 5856 | /// Convert character array `str` of length `len` to hexadecimal. |
| 5857 | std::string ToHex(const unsigned char * str, int len) { |
| 5858 | stringstream ss; |
| 5859 | ss << hex << std::uppercase << setfill('0'); |
| 5860 | for (int i = 0; i < len; ++i) { |
| 5861 | // setw is not sticky. stringstream only converts integral values, |
| 5862 | // so a cast to int is required, but only convert the least significant byte to hex. |
| 5863 | ss << setw(2) << (static_cast<int32_t>(str[i]) & 0xFF); |
| 5864 | } |
| 5865 | std::string result = ss.str(); |
| 5866 | boost::to_lower(result); |
| 5867 | return result; |
| 5868 | } |
| 5869 | |
| 5870 | TEST_P(ExprTest, SHAFunctions) { |
| 5871 | unsigned char input[] = "compute sha digest"; |