* @license GPLv2
*/
-#include "util.h"
+#include "util.hpp"
#include <sstream>
+#include <iomanip>
#include <openssl/evp.h>
#include <boost/algorithm/string.hpp>
if ( EVP_DigestInit_ex(&mdctx, md, NULL) == 0 )
{
EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
- EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Could not set up digest context correctly");
}
if ( data.empty() )
{
EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
- EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Passed data is empty");
}
if ( EVP_DigestUpdate(&mdctx, data.c_str(), data.size()) == 0 )
{
EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
- EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Could not hash data into digest context");
}
if ( EVP_DigestFinal_ex(&mdctx, md_value, &md_len) == 0 )
{
EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
- EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Could not retrieve digest value");
}
if ( (md_len == 0) || (EVP_MD_CTX_size(&mdctx) == 0) )
{
EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
- EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Retrieved invalid digest value");
}
// Internal cleanup of the digest content.
EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
- EVP_cleanup(); /*lint !e534 */
// Convert md5 digest C string to hex.
std::ostringstream oss_digest_md5_hex;
{
// We have to do a static cast to an decimal representation, cause otherwise ostringstream would interpret
// the stream as a character and output the character representation of the hex value.
- oss_digest_md5_hex << std::hex << static_cast<unsigned short>(md_value[i]);
+ oss_digest_md5_hex << std::nouppercase << std::setw(2) << std::setfill('0')
+ << std::hex << static_cast<int>(static_cast<unsigned char>(md_value[i]));
}
return oss_digest_md5_hex.str();
/**
* Get the status code from the given data.
- * @param data The data containing the status code at front, limited by " ".
- * @return The parsed status code.
- */
-std::string parse_status_code(std::string data)
-{
- std::list<std::string> tokens;
- boost::algorithm::split(tokens,data,boost::is_any_of(" "));
- if ( tokens.empty() )
- return "";
- return tokens.front();
-}
-
-
-/**
- * Get the status code from the given data.
- * @param data The data containing the status code at front, limited by " ".
+ * @param data The data containing the status code at front, limited by delimiter.
* @param delimiter The delimiter to use.
- * @return The parsed status code.
+ * @return The parsed status code
*/
std::string parse_status_code(std::string data, std::string delimiter)
{