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