@@ -211,11 +211,11 @@ const std::vector<MaskedATREntry> MASKED_ATRS = {
211211 constructor<ElectronicID::Type::LuxEID>},
212212};
213213
214- const auto SUPPORTED_ALGORITHMS = std::map<std::string , HashAlgorithm> {
215- {" SHA-224" s , HashAlgorithm::SHA224}, {" SHA-256" s , HashAlgorithm::SHA256},
216- {" SHA-384" s , HashAlgorithm::SHA384}, {" SHA-512" s , HashAlgorithm::SHA512},
217- {" SHA3-224" s , HashAlgorithm::SHA3_224}, {" SHA3-256" s , HashAlgorithm::SHA3_256},
218- {" SHA3-384" s , HashAlgorithm::SHA3_384}, {" SHA3-512" s , HashAlgorithm::SHA3_512},
214+ const auto SUPPORTED_ALGORITHMS = std::map<std::string_view , HashAlgorithm> {
215+ {" SHA-224" , HashAlgorithm::SHA224}, {" SHA-256" , HashAlgorithm::SHA256},
216+ {" SHA-384" , HashAlgorithm::SHA384}, {" SHA-512" , HashAlgorithm::SHA512},
217+ {" SHA3-224" , HashAlgorithm::SHA3_224}, {" SHA3-256" , HashAlgorithm::SHA3_256},
218+ {" SHA3-384" , HashAlgorithm::SHA3_384}, {" SHA3-512" , HashAlgorithm::SHA3_512},
219219};
220220
221221} // namespace
@@ -288,68 +288,71 @@ HashAlgorithm::HashAlgorithm(const std::string& algoName)
288288 value = SUPPORTED_ALGORITHMS.at (algoName);
289289}
290290
291- HashAlgorithm::operator std::string () const
291+ HashAlgorithm::operator std::string_view () const noexcept
292292{
293293 const auto algoNameValuePair =
294294 std::find_if (SUPPORTED_ALGORITHMS.cbegin (), SUPPORTED_ALGORITHMS.cend (),
295295 [this ](const auto & pair) { return pair.second == value; });
296- return algoNameValuePair != SUPPORTED_ALGORITHMS.cend () ? algoNameValuePair->first : " UNKNOWN" ;
296+ if (algoNameValuePair != SUPPORTED_ALGORITHMS.cend ())
297+ return algoNameValuePair->first ;
298+ return " UNKNOWN" ;
297299}
298300
299301std::string HashAlgorithm::allSupportedAlgorithmNames ()
300302{
301303 static const auto SUPPORTED_ALGORITHM_NAMES = std::accumulate (
302304 std::next (SUPPORTED_ALGORITHMS.begin ()), SUPPORTED_ALGORITHMS.end (),
303305 std::string (SUPPORTED_ALGORITHMS.begin ()->first ),
304- [](auto result, const auto & value) { return result + " , " s + std::string (value.first ); });
306+ [](auto result, const auto & value) { return ( result + " , " ). append (value.first ); });
305307 return SUPPORTED_ALGORITHM_NAMES;
306308}
307309
308310pcsc_cpp::byte_vector HashAlgorithm::rsaOID (const HashAlgorithmEnum hash)
309311{
310312 switch (hash) {
311- case HashAlgorithm::SHA224:
313+ using enum HashAlgorithm::HashAlgorithmEnum;
314+ case SHA224:
312315 return {0x30 , 0x2d , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
313316 0x65 , 0x03 , 0x04 , 0x02 , 0x04 , 0x05 , 0x00 , 0x04 , 0x1c };
314- case HashAlgorithm:: SHA256:
317+ case SHA256:
315318 return {0x30 , 0x31 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
316319 0x65 , 0x03 , 0x04 , 0x02 , 0x01 , 0x05 , 0x00 , 0x04 , 0x20 };
317- case HashAlgorithm:: SHA384:
320+ case SHA384:
318321 return {0x30 , 0x41 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
319322 0x65 , 0x03 , 0x04 , 0x02 , 0x02 , 0x05 , 0x00 , 0x04 , 0x30 };
320- case HashAlgorithm:: SHA512:
323+ case SHA512:
321324 return {0x30 , 0x51 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
322325 0x65 , 0x03 , 0x04 , 0x02 , 0x03 , 0x05 , 0x00 , 0x04 , 0x40 };
323- case HashAlgorithm:: SHA3_224:
326+ case SHA3_224:
324327 return {0x30 , 0x2d , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
325328 0x65 , 0x03 , 0x04 , 0x02 , 0x07 , 0x05 , 0x00 , 0x04 , 0x1c };
326- case HashAlgorithm:: SHA3_256:
329+ case SHA3_256:
327330 return {0x30 , 0x31 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
328331 0x65 , 0x03 , 0x04 , 0x02 , 0x08 , 0x05 , 0x00 , 0x04 , 0x20 };
329- case HashAlgorithm:: SHA3_384:
332+ case SHA3_384:
330333 return {0x30 , 0x41 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
331334 0x65 , 0x03 , 0x04 , 0x02 , 0x09 , 0x05 , 0x00 , 0x04 , 0x30 };
332- case HashAlgorithm:: SHA3_512:
335+ case SHA3_512:
333336 return {0x30 , 0x51 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
334337 0x65 , 0x03 , 0x04 , 0x02 , 0x0A , 0x05 , 0x00 , 0x04 , 0x40 };
335338 default :
336339 THROW (ArgumentFatalError, " No OID for algorithm " + std::string (HashAlgorithm (hash)));
337340 }
338341}
339342
340- CertificateType::operator std::string () const
343+ CertificateType::operator std::string () const noexcept
341344{
342- return std::string ( magic_enum::enum_name (value) );
345+ return magic_enum::enum_name (value);
343346}
344347
345- JsonWebSignatureAlgorithm::operator std::string () const
348+ JsonWebSignatureAlgorithm::operator std::string_view () const noexcept
346349{
347- return std::string ( magic_enum::enum_name (value) );
350+ return magic_enum::enum_name (value);
348351}
349352
350- SignatureAlgorithm::operator std::string () const
353+ SignatureAlgorithm::operator std::string_view () const noexcept
351354{
352- return std::string ( magic_enum::enum_name (value) );
355+ return magic_enum::enum_name (value);
353356}
354357
355358} // namespace electronic_id
0 commit comments