本文整理汇总了C++中fromHex函数的典型用法代码示例。如果您正苦于以下问题:C++ fromHex函数的具体用法?C++ fromHex怎么用?C++ fromHex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromHex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parsePercentEncoding
static QByteArray parsePercentEncoding(const QByteArray &in)
{
QByteArray out;
for(int n = 0; n < in.size(); ++n)
{
char c = in[n];
if(c == '%')
{
if(n + 2 >= in.size())
return QByteArray();
int hi = fromHex(in[n + 1]);
if(hi == -1)
return QByteArray();
int lo = fromHex(in[n + 2]);
if(lo == -1)
return QByteArray();
unsigned char val = (hi << 4) + lo;
out += val;
n += 2; // adjust position
}
else
out += c;
}
return out;
}
开发者ID:mcspring,项目名称:pushpin,代码行数:32,代码来源:requestsession.cpp
示例2: GetCBOREncoding
byte * GetCBOREncoding(const cn_cbor * pControl, int * pcbEncoded)
{
const cn_cbor * pOutputs = cn_cbor_mapget_string(pControl, "output");
const cn_cbor * pCBOR;
byte * pb = NULL;
const byte * pb2;
int i;
if ((pOutputs == NULL) || (pOutputs->type != CN_CBOR_MAP)) {
fprintf(stderr, "Invalid output\n");
exit(1);
}
pCBOR = cn_cbor_mapget_string(pOutputs, "cbor");
if ((pCBOR == NULL) || (pCBOR->type != CN_CBOR_TEXT)) {
fprintf(stderr, "Invalid cbor object");
exit(1);
}
pb = malloc(pCBOR->length / 2);
pb2 = pCBOR->v.bytes;
for (i = 0; i < pCBOR->length; i += 2) {
pb[i / 2] = fromHex(pb2[i]) * 16 + fromHex(pb2[i + 1]);
}
*pcbEncoded = (int) (pCBOR->length / 2);
return pb;
}
开发者ID:cose-wg,项目名称:COSE-C,代码行数:29,代码来源:test.c
示例3: if
std::string CEncrypt::urlDecode(std::string strVal)
{
const char *pszVal = strVal.c_str();
std::string strTemp = "";
size_t iLens = strVal.size();
for (size_t i = 0; i < iLens; i++)
{
if ('+' == pszVal[i])
{
strTemp += ' ';
}
else if ('%' == pszVal[i])
{
assert(i + 2 < iLens);
unsigned char cHigh = fromHex((unsigned char)pszVal[++i]);
unsigned char cLow = fromHex((unsigned char)pszVal[++i]);
strTemp += cHigh*16 + cLow;
}
else
{
strTemp += pszVal[i];
}
}
return strTemp;
}
开发者ID:idleness,项目名称:QService,代码行数:29,代码来源:Encrypt.cpp
示例4: check
static bool check(
bool ok,
const uint8_t *rmdHex,
const uint8_t *dataHex
) {
uint8_t rmd[kRIPEMD160ByteSize];
fromHex(rmd, rmdHex, kRIPEMD160ByteSize, false);
uint8_t data[1024];
auto dataLen = strlen((const char*)dataHex)/2;
if(0<dataLen) {
fromHex(data, dataHex, dataLen, false);
}
uint8_t cmp[kRIPEMD160ByteSize];
rmd160(cmp, data, dataLen);
TEST_CHECK(
ok,
0==memcmp(cmp, rmd, sizeof(rmd)),
"RIPEMD-160 fails for %s\n",
dataHex
);
return ok;
}
开发者ID:brishtiteveja,项目名称:bitiodine,代码行数:25,代码来源:ripemd-160_t.cpp
示例5: readVector
static void readVector(char * pszVec,
unsigned int cbVec, octet * pabVec)
{
unsigned int i = cbVec;
memset(pabVec, 0, cbVec);
for ( ; i && pszVec[0] && pszVec[1]; pszVec += 2, pabVec++, i--) {
*pabVec = (fromHex(pszVec[0]) << 4) | fromHex(pszVec[1]);
}
if (!i && *pszVec) printUsage(1);
}
开发者ID:edolstra,项目名称:aefs,代码行数:10,代码来源:testcipher.c
示例6: fromHex
bool Color::fromString(const string &str)
{
if(str.length() != 4 && str.length() != 7)
return false;
if(str[0] != '#') return false;
for(string::size_type i = 1; i < str.length(); ++i) {
if(!isxdigit((int)str[i]))
return false;
}
if(str.length() == 7) {
m_red = (__uint8)( (fromHex(str[1]) << 4) + fromHex(str[2]) );
m_green = (__uint8)( (fromHex(str[3]) << 4) + fromHex(str[4]) );
m_blue = (__uint8)( (fromHex(str[5]) << 4) + fromHex(str[6]) );
} else {
__uint8 v = fromHex(str[1]);
m_red = (__uint8)( (v << 4) + v );
v = fromHex(str[2]);
m_green = (__uint8)( (v << 4) + v );
v = fromHex(str[3]);
m_blue = (__uint8)( (v << 4) + v );
}
m_alpha = 255;
return true;
}
开发者ID:mneumann,项目名称:tulip,代码行数:31,代码来源:graphics.cpp
示例7: FromHex
byte * FromHex(const char * rgch, int cch)
{
byte * pb = malloc(cch / 2);
const char * pb2 = rgch;
int i;
for (i = 0; i < cch; i += 2) {
pb[i / 2] = fromHex(pb2[i]) * 16 + fromHex(pb2[i + 1]);
}
return pb;
}
开发者ID:cose-wg,项目名称:COSE-C,代码行数:12,代码来源:test.c
示例8: hex_decode
Bytes hex_decode(const String& string)
{
Bytes ret;
ret.reserve(string.length()/2);
for (auto i: range(0, (string.length()/2)*2, 2))
{
if (!isHex(string[i]) || !isHex(string[i+1])) break;
ret.push_back((fromHex(string[i]) << 4) | fromHex(string[i+1]));
}
return ret;
}
开发者ID:Qarterd,项目名称:Honeycomb,代码行数:12,代码来源:Encode.cpp
示例9: THROW
Derived Id<n, Derived>::FromString(const String& string)
{
if(string.length() != n * 2)
THROW(String("Wrong length of id string for ") + typeid(Derived).name());
Derived id;
for(int i = 0; i < n; ++i)
id.data[i] = (fromHex(string[i * 2]) << 4) | fromHex(string[i * 2 + 1]);
return id;
}
开发者ID:quyse,项目名称:oil,代码行数:12,代码来源:Id.cpp
示例10: crypt
bool WPUtils::crypt(bool isEncrypt, const QByteArray & in,
QByteArray & out) {
QByteArray key, iv;
QString fail;
if (!fromHex(_key, key)) {
fail += "Key is not valid hex. ";
}
if (!fromHex(_iv, iv)) {
fail += "IV is not valid hex. ";
}
if (!fail.isEmpty()) {
qDebug() << "fail = " << fail;
//toast(fail);
return false;
}
AESParams params(globalContext);
if (!params.isValid()) {
//toast(
qDebug () << "fails = " << QString("Could not create params. %1").arg(SBError::getErrorText(params.lastError()));
return false;
}
AESKey aesKey(params, key);
if (!aesKey.isValid()) {
qDebug() << "failes = " << QString("Could not create a key. %1").arg(SBError::getErrorText(aesKey.lastError()));
return false;
}
int rc;
if (isEncrypt) {
rc = hu_AESEncryptMsg(params.aesParams(), aesKey.aesKey(), iv.length(),
(const unsigned char*) iv.constData(), in.length(),
(const unsigned char *) in.constData(),
(unsigned char *) out.data(), globalContext.ctx());
} else {
rc = hu_AESDecryptMsg(params.aesParams(), aesKey.aesKey(), iv.length(),
(const unsigned char*) iv.constData(), in.length(),
(const unsigned char *) in.constData(),
(unsigned char *) out.data(), globalContext.ctx());
}
if (rc == SB_SUCCESS) {
return true;
}
//toast
qDebug() << QString("Crypto operation failed. %1").arg(SBError::getErrorText(rc));
return false;
}
开发者ID:b0unc3,项目名称:WordPress-bb10,代码行数:52,代码来源:WPUtils.cpp
示例11: convertColorFromString
QColor convertColorFromString(const QString &s)
{
if (s.length() == 9 && s.startsWith(QLatin1Char('#'))) {
uchar a = fromHex(s, 1);
uchar r = fromHex(s, 3);
uchar g = fromHex(s, 5);
uchar b = fromHex(s, 7);
return QColor(r, g, b, a);
} else {
QColor rv(s);
return rv;
}
}
开发者ID:jay602,项目名称:QmlDesignerPlus,代码行数:13,代码来源:propertyeditorcontextobject.cpp
示例12: fromHex
QColor QDeclarativeStringConverters::colorFromString(const QString &s, bool *ok)
{
if (s.length() == 9 && s.startsWith(QLatin1Char('#'))) {
uchar a = fromHex(s, 1);
uchar r = fromHex(s, 3);
uchar g = fromHex(s, 5);
uchar b = fromHex(s, 7);
if (ok) *ok = true;
return QColor(r, g, b, a);
} else {
QColor rv(s);
if (ok) *ok = rv.isValid();
return rv;
}
}
开发者ID:Blizzard,项目名称:qt4,代码行数:15,代码来源:qdeclarativestringconverters.cpp
示例13: ReadPrefHex
uint32_t ReadPrefHex(const char* pref_key)
{
LoadConfigFile();
std::string pref = "preferences:";
pref.append(pref_key);
return fromHex(iniparser_getstring(preferences, pref.c_str(), 0));
}
开发者ID:ElementW,项目名称:visualboyadvance-m,代码行数:7,代码来源:ConfigManager.cpp
示例14: cipher
void CiscoSecret7::transform(const QByteArray &input, QByteArray &output)
{
if (wayValue == INBOUND) {
QByteArray data;
cipher(seed,input, data);
output = data.toHex().prepend(QByteArray::number(seed));
} else {
QByteArray encrypted = input.toUpper();
if (encrypted.isEmpty())
return;
if (encrypted.size() < 3) {
emit error(tr("Invalid hash (far too small)"),id);
return;
}
bool k = true;
seed = encrypted.mid(0,2).toInt(&k);
if (!k || seed > MAXSEED) {
emit error(tr("Invalid seed, it must be an unsigned integer <= %1").arg(MAXSEED),id);
return;
}
QByteArray data = encrypted.mid(2);
data = fromHex(data);
cipher(seed,data,output);
}
}
开发者ID:nccgroup,项目名称:pip3line,代码行数:30,代码来源:ciscosecret7.cpp
示例15: testAddr2Hash
static bool testAddr2Hash(
const uint8_t *addr,
const uint8_t *hexHash
) {
uint8_t result[kRIPEMD160ByteSize];
auto ok = addrToHash160(result, addr, true);
TEST_CHECK(ok, ok, "failed to decode address %s", addr);
uint8_t hash[kRIPEMD160ByteSize];
fromHex(hash, (const uint8_t*)hexHash, kRIPEMD160ByteSize, false);
uint8_t hexResult[1 + 2*kRIPEMD160ByteSize];
toHex(hexResult, result, kRIPEMD160ByteSize, false);
TEST_CHECK(
ok,
0==memcmp(result, hash, kRIPEMD160ByteSize),
"decode fail\n"
" for addr: %s\n"
" expected: %s\n"
" got: %s\n"
"\n",
addr,
hexHash,
hexResult
);
return ok;
}
开发者ID:brishtiteveja,项目名称:bitiodine,代码行数:29,代码来源:base58_t.cpp
示例16: fromHex
bool Currency::generateGenesisBlock() {
m_genesisBlock = boost::value_initialized<Block>();
// Hard code coinbase tx in genesis block, because "tru" generating tx use random, but genesis should be always the same
std::string genesisCoinbaseTxHex = GENESIS_COINBASE_TX_HEX;
BinaryArray minerTxBlob;
bool r =
fromHex(genesisCoinbaseTxHex, minerTxBlob) &&
fromBinaryArray(m_genesisBlock.baseTransaction, minerTxBlob);
if (!r) {
logger(ERROR, BRIGHT_RED) << "failed to parse coinbase tx from hard coded blob";
return false;
}
m_genesisBlock.majorVersion = BLOCK_MAJOR_VERSION_1;
m_genesisBlock.minorVersion = BLOCK_MINOR_VERSION_0;
m_genesisBlock.timestamp = GENESIS_TIMESTAMP;
m_genesisBlock.nonce = GENESIS_NONCE;
if (m_testnet) {
++m_genesisBlock.nonce;
}
//miner::find_nonce_for_given_block(bl, 1, 0);
return true;
}
开发者ID:shadow743,项目名称:SAUnitedCoin,代码行数:27,代码来源:Currency.cpp
示例17: unpackQP
static void unpackQP(struct MHINFO *w)
{
uchar val;
char c, d, *q, *r;
for (q = r = w->start; q < w->end; ++q) {
c = *q;
if (c != '=') {
*r++ = c;
continue;
}
c = *++q;
if (c == '\n')
continue;
d = q[1];
if (isxdigit(c) && isxdigit(d)) {
d = fromHex(c, d);
if (d == 0)
d = ' ';
*r++ = d;
++q;
continue;
}
--q;
*r++ = '=';
}
w->end = r;
*r = 0;
} /* unpackQP */
开发者ID:williamh,项目名称:edbrowse,代码行数:28,代码来源:fetchmail.c
示例18: verify
void OID::init( const std::string& s ) {
verify( s.size() == 24 );
const char *p = s.c_str();
for( size_t i = 0; i < kOIDSize; i++ ) {
data[i] = fromHex(p);
p += 2;
}
}
开发者ID:328500920,项目名称:mongo,代码行数:8,代码来源:oid.cpp
示例19: verify
void OID::init( string s ) {
verify( s.size() == 24 );
const char *p = s.c_str();
for( int i = 0; i < 12; i++ ) {
data[i] = fromHex(p);
p += 2;
}
}
开发者ID:89snake89,项目名称:mongo,代码行数:8,代码来源:oid.cpp
示例20: hexDecode
std::string hexDecode(const std::string& data)
{
std::string result(data.length() / 2, '-');
for (unsigned i = 0; i < result.length(); ++i)
result[i] = fromHex(data[2 * i], data[2 * i + 1]);
return result;
}
开发者ID:913862627,项目名称:wt,代码行数:9,代码来源:Utils.C
注:本文中的fromHex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论