@@ -209,11 +209,11 @@ const std::vector<MaskedATREntry> MASKED_ATRS = {
209209 constructor<ElectronicID::Type::LuxEID>},
210210};
211211
212- const auto SUPPORTED_ALGORITHMS = std::map<std::string , HashAlgorithm> {
213- {" SHA-224" s , HashAlgorithm::SHA224 }, {" SHA-256" s , HashAlgorithm::SHA256 },
214- {" SHA-384" s , HashAlgorithm::SHA384 }, {" SHA-512" s , HashAlgorithm::SHA512 },
215- {" SHA3-224" s , HashAlgorithm::SHA3_224 }, {" SHA3-256" s , HashAlgorithm::SHA3_256 },
216- {" SHA3-384" s , HashAlgorithm::SHA3_384 }, {" SHA3-512" s , HashAlgorithm::SHA3_512 },
212+ const auto SUPPORTED_ALGORITHMS = std::map<std::string_view , HashAlgorithm> {
213+ {" SHA-224" , HashAlgorithm::SHA224 }, {" SHA-256" , HashAlgorithm::SHA256 },
214+ {" SHA-384" , HashAlgorithm::SHA384 }, {" SHA-512" , HashAlgorithm::SHA512 },
215+ {" SHA3-224" , HashAlgorithm::SHA3_224 }, {" SHA3-256" , HashAlgorithm::SHA3_256 },
216+ {" SHA3-384" , HashAlgorithm::SHA3_384 }, {" SHA3-512" , HashAlgorithm::SHA3_512 },
217217};
218218
219219} // namespace
@@ -263,14 +263,14 @@ bool ElectronicID::isSupportedSigningHashAlgorithm(const HashAlgorithm hashAlgo)
263263}
264264
265265AutoSelectFailed::AutoSelectFailed (Reason r) :
266- Error (std::string(" Auto-select card failed, reason: " ) + std::string (magic_enum::enum_name(r))),
266+ Error (std::string(" Auto-select card failed, reason: " ).append (magic_enum::enum_name(r))),
267267 _reason (r)
268268{
269269}
270270
271271VerifyPinFailed::VerifyPinFailed (const Status s, const observer_ptr<pcsc_cpp::ResponseApdu> ra,
272272 const int8_t r) :
273- Error(std::string(" Verify PIN failed, status: " ) + std::string (magic_enum::enum_name(s))
273+ Error(std::string(" Verify PIN failed, status: " ).append (magic_enum::enum_name(s))
274274 + (ra ? " , response: " + *ra : " " )),
275275 _status(s), _retries(r)
276276{
@@ -286,68 +286,71 @@ HashAlgorithm::HashAlgorithm(const std::string& algoName)
286286 value = SUPPORTED_ALGORITHMS .at (algoName);
287287}
288288
289- HashAlgorithm::operator std::string () const
289+ HashAlgorithm::operator std::string_view () const noexcept
290290{
291291 const auto algoNameValuePair =
292292 std::find_if (SUPPORTED_ALGORITHMS .cbegin (), SUPPORTED_ALGORITHMS .cend (),
293293 [this ](const auto & pair) { return pair.second == value; });
294- return algoNameValuePair != SUPPORTED_ALGORITHMS .cend () ? algoNameValuePair->first : " UNKNOWN" ;
294+ if (algoNameValuePair != SUPPORTED_ALGORITHMS .cend ())
295+ return algoNameValuePair->first ;
296+ return " UNKNOWN" ;
295297}
296298
297299std::string HashAlgorithm::allSupportedAlgorithmNames ()
298300{
299301 static const auto SUPPORTED_ALGORITHM_NAMES = std::accumulate (
300302 std::next (SUPPORTED_ALGORITHMS .begin ()), SUPPORTED_ALGORITHMS .end (),
301303 std::string (SUPPORTED_ALGORITHMS .begin ()->first ),
302- [](auto result, const auto & value) { return result + " , " s + std::string (value.first ); });
304+ [](auto result, const auto & value) { return ( result + " , " ). append (value.first ); });
303305 return SUPPORTED_ALGORITHM_NAMES ;
304306}
305307
306308pcsc_cpp::byte_vector HashAlgorithm::rsaOID (const HashAlgorithmEnum hash)
307309{
308310 switch (hash) {
309- case HashAlgorithm::SHA224 :
311+ using enum HashAlgorithm::HashAlgorithmEnum;
312+ case SHA224 :
310313 return {0x30 , 0x2d , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
311314 0x65 , 0x03 , 0x04 , 0x02 , 0x04 , 0x05 , 0x00 , 0x04 , 0x1c };
312- case HashAlgorithm:: SHA256 :
315+ case SHA256 :
313316 return {0x30 , 0x31 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
314317 0x65 , 0x03 , 0x04 , 0x02 , 0x01 , 0x05 , 0x00 , 0x04 , 0x20 };
315- case HashAlgorithm:: SHA384 :
318+ case SHA384 :
316319 return {0x30 , 0x41 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
317320 0x65 , 0x03 , 0x04 , 0x02 , 0x02 , 0x05 , 0x00 , 0x04 , 0x30 };
318- case HashAlgorithm:: SHA512 :
321+ case SHA512 :
319322 return {0x30 , 0x51 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
320323 0x65 , 0x03 , 0x04 , 0x02 , 0x03 , 0x05 , 0x00 , 0x04 , 0x40 };
321- case HashAlgorithm:: SHA3_224 :
324+ case SHA3_224 :
322325 return {0x30 , 0x2d , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
323326 0x65 , 0x03 , 0x04 , 0x02 , 0x07 , 0x05 , 0x00 , 0x04 , 0x1c };
324- case HashAlgorithm:: SHA3_256 :
327+ case SHA3_256 :
325328 return {0x30 , 0x31 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
326329 0x65 , 0x03 , 0x04 , 0x02 , 0x08 , 0x05 , 0x00 , 0x04 , 0x20 };
327- case HashAlgorithm:: SHA3_384 :
330+ case SHA3_384 :
328331 return {0x30 , 0x41 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
329332 0x65 , 0x03 , 0x04 , 0x02 , 0x09 , 0x05 , 0x00 , 0x04 , 0x30 };
330- case HashAlgorithm:: SHA3_512 :
333+ case SHA3_512 :
331334 return {0x30 , 0x51 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
332335 0x65 , 0x03 , 0x04 , 0x02 , 0x0A , 0x05 , 0x00 , 0x04 , 0x40 };
333336 default :
334337 THROW (ArgumentFatalError, " No OID for algorithm " + std::string (HashAlgorithm (hash)));
335338 }
336339}
337340
338- CertificateType::operator std::string () const
341+ CertificateType::operator std::string_view () const noexcept
339342{
340- return std::string ( magic_enum::enum_name (value) );
343+ return magic_enum::enum_name (value);
341344}
342345
343- JsonWebSignatureAlgorithm::operator std::string () const
346+ JsonWebSignatureAlgorithm::operator std::string_view () const noexcept
344347{
345- return std::string ( magic_enum::enum_name (value) );
348+ return magic_enum::enum_name (value);
346349}
347350
348- SignatureAlgorithm::operator std::string () const
351+ SignatureAlgorithm::operator std::string_view () const noexcept
349352{
350- return std::string ( magic_enum::enum_name (value) );
353+ return magic_enum::enum_name (value);
351354}
352355
353356} // namespace electronic_id
0 commit comments