Crypto++  5.6.5
Free C++ class library of cryptographic schemes
hex.cpp
1 // hex.cpp - 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 
9 NAMESPACE_BEGIN(CryptoPP)
10 
11 namespace
12 {
13  const byte s_vecUpper[] = "0123456789ABCDEF";
14  const byte s_vecLower[] = "0123456789abcdef";
15 }
16 
18 {
19  bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);
20  m_filter->Initialize(CombinedNameValuePairs(
21  parameters,
22  MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true)));
23 }
24 
26 {
28  parameters,
29  MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true)));
30 }
31 
32 const int *HexDecoder::GetDefaultDecodingLookupArray()
33 {
34  static volatile bool s_initialized = false;
35  static int s_array[256];
36 
37  if (!s_initialized)
38  {
39  InitializeDecodingLookupArray(s_array, s_vecUpper, 16, true);
40  s_initialized = true;
41  }
42  return s_array;
43 }
44 
45 NAMESPACE_END
46 
47 #endif
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Definition: cryptlib.h:349
Combines two sets of NameValuePairs.
Definition: algparam.h:135
static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive)
Intializes BaseN lookup array.
Definition: basecode.cpp:178
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: hex.cpp:17
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: basecode.cpp:115
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:563
Classes for HexEncoder and HexDecoder.
Crypto++ library namespace.
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: hex.cpp:25
Interface for retrieving values given their names.
Definition: cryptlib.h:278