Crypto++ 8.9
Free C++ class library of cryptographic schemes
hex.cpp
1// hex.cpp - originally written and placed in the public domain by Wei Dai
2
3#include "pch.h"
4
5#ifndef CRYPTOPP_IMPORTS
6
7#include "hex.h"
8
9NAMESPACE_BEGIN(CryptoPP)
10ANONYMOUS_NAMESPACE_BEGIN
11
12const byte s_vecUpper[] = "0123456789ABCDEF";
13const byte s_vecLower[] = "0123456789abcdef";
14const int s_array[256] = {
15 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
16 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
17 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
18 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
19 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
20 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
21 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
22 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
23 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
24 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
25 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
26 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
27 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
28 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
29 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
30 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
31};
32
33ANONYMOUS_NAMESPACE_END
34
36{
37 bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);
38 m_filter->Initialize(CombinedNameValuePairs(
39 parameters,
40 MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true)));
41}
42
44{
46 parameters,
47 MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true)));
48}
49
50// Unrolled initialization, http://github.com/weidai11/cryptopp/issues/376
51const int *HexDecoder::GetDefaultDecodingLookupArray()
52{
53 return s_array;
54}
55
56NAMESPACE_END
57
58#endif // CRYPTOPP_IMPORTS
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition algparam.h:508
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Combines two sets of NameValuePairs.
Definition algparam.h:129
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Interface for retrieving values given their names.
Definition cryptlib.h:327
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Definition cryptlib.h:397
Classes for HexEncoder and HexDecoder.
Crypto++ library namespace.
Namespace containing value name definitions.
Definition argnames.h:13
const char * DecodingLookupArray()
const byte *
Definition argnames.h:76
const char * EncodingLookupArray()
const byte *
Definition argnames.h:75
const char * Uppercase()
bool
Definition argnames.h:70
const char * Log2Base()
int
Definition argnames.h:74
Precompiled header file.