55 const std::string& algoName,
const bool lookInAltNames)
59 if (!ChecksumFactory::getAlgorithmId(
id, algoName, lookInAltNames))
60 id = ChecksumAlgoId::Invalid;
62 initialise(provider,
id);
76 initialise(provider, type);
88 ChecksumFormatter::ChecksumFormatter(
const bool uc,
const NumericBase nb,
93 setSpacesPositions(sp);
120 string ChecksumFormatter::format(
const uint8_t* value,
const size_t size)
122 if (value ==
nullptr || size == 0)
125 string byteFormatter;
126 switch (getNumericBase())
128 case NumericBase::octal :
129 byteFormatter =
"%03o";
131 case NumericBase::decimal :
132 byteFormatter =
"%03u";
135 byteFormatter = (getUpperCase()) ?
"%02X" :
"%02x";
139 size_t lastSpacePos = size - 1;
140 constexpr
size_t bufSize = 4;
142 for (
size_t i = 0; i < size; i++)
144 snprintf(buf, bufSize, byteFormatter.c_str(),
static_cast<uint_fast16_t
>(value[i]));
147 if (i < lastSpacePos && std::find(spacesPos.begin(), spacesPos.end(),
static_cast<unsigned int>(i)) != spacesPos.end())
161 bool ChecksumFormatter::getUpperCase()
const
174 void ChecksumFormatter::setUpperCase(
const bool isUpperCase)
176 upperCase = isUpperCase;
204 case NumericBase::hexadecimal :
205 case NumericBase::octal :
206 case NumericBase::decimal :
210 numericBase = NumericBase::hexadecimal;
237 void ChecksumFormatter::setSpacesPositions(
const std::string& spacesPositions)
239 Positions sp = toSpacesPositions(spacesPositions);
241 setSpacesPositions(sp);
251 void ChecksumFormatter::setSpacesPositions(
const Positions& spacesPositions)
253 spacesPos = spacesPositions;
270 const uint8_t* value,
const size_t size,
271 const std::string& algoName,
272 const bool lookInAltNames)
276 if (!ChecksumFactory::getAlgorithmId(
id, algoName, lookInAltNames))
277 id = ChecksumAlgoId::Invalid;
279 return format(provider, value, size,
id);
294 const uint8_t* value,
const size_t size,
298 return ckf.
format(value, size);
330 const regex re(R
"(\s*[,]\s*)");
331 sregex_token_iterator it{ spacesPositions.begin(), spacesPositions.end(), re, -1 };
333 ssp.erase(std::remove_if(ssp.begin(), ssp.end(), [](
string const& s) {
334 return s.empty(); }),
338 for (
string token : ssp)
344 sp.insert(
static_cast<uint_fast16_t
>(lPos));
Classes for enumerate and create all the checksums' algorithms that the application knows.
Stores the value of a checksum.
ChecksumAlgoId getType() const
Gets the type of the checksum.
const uint8_t * getValue() const
Gets the value of the checksum.
size_t getSize() const
Gets the size of the checksum's value.
ChecksumAlgoId
Ids of algorithms of checksums.
std::vector< std::string > ArrayString
Array of strings.