X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tadcore%2FTADCCore%2FTADC_Util.cpp;h=bde66c40e9b23b7322c842494da890a6f6a1ac92;hb=117edfd189a224f406654195a2fbfedc81e966df;hp=4f08b0718765f47aed1b9e18ef4f3bd57c994d54;hpb=99cebf960a4f71ba7e01c5761a3f4c05d90a5036;p=platform%2Fcore%2Fsecurity%2Fdrm-service-core-tizen.git diff --git a/tadcore/TADCCore/TADC_Util.cpp b/tadcore/TADCCore/TADC_Util.cpp index 4f08b07..bde66c4 100644 --- a/tadcore/TADCCore/TADC_Util.cpp +++ b/tadcore/TADCCore/TADC_Util.cpp @@ -20,6 +20,8 @@ #include "TADC_IF.h" #include "TADC_ErrorCode.h" +#include + // -------------------------- Base64 -------------------------------- static CHAR __base64_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', @@ -166,30 +168,20 @@ LPBYTE Base64Decode(LPCSTR pszString, int *pnLength) int HEX2BIN(LPCSTR pszHex, LPBYTE baBin, int *pnLength) { - CHAR szTemp[3]; - CHAR szHex[1024]; - int i = 0, nLength = 0; - - nLength = TADC_IF_StrLen(pszHex); - - if (nLength <= 0) + int hexLen = strlen(pszHex); + if (hexLen <= 0) return -1; - if ((nLength % 2) == 0) { - TADC_IF_StrNCpy(szHex, pszHex, nLength); - } else { - szHex[0] = '0'; - TADC_IF_StrNCpy(&szHex[1], pszHex, nLength); - nLength += 1; + std::string hex(pszHex); + if ((hexLen % 2) != 0) { + hex.insert(0, "0"); + hexLen++; } - *pnLength = nLength / 2; - szTemp[2] = 0; - - for (i = 0; i < *pnLength; i++) { - szTemp[0] = szHex[i * 2]; - szTemp[1] = szHex[i * 2 + 1]; - baBin[i] = (BYTE)strtoul(szTemp, NULL, 16); + *pnLength = hexLen / 2; + for (int i = 0; i < *pnLength; i++) { + char buf[3] = {hex.at(i * 2), hex.at(i * 2 +1), '\0'}; + baBin[i] = (BYTE)strtoul(buf, NULL, 16); } return 0;