38 throw std::logic_error(
"Public key is not initialized");
41 const int key_type = EVP_PKEY_get_base_id(
key);
43 if (key_type == EVP_PKEY_EC)
48 std::string gname(gname_len + 1,
'\0');
50 EVP_PKEY_get_group_name(
key, gname.data(), gname.size(), &gname_len));
51 gname.resize(gname_len);
54 if (gname == SN_X9_62_prime256v1)
58 throw std::domain_error(fmt::format(
59 "secp256r1 key cannot be used with COSE algorithm {}", cose_alg));
62 else if (gname == SN_secp384r1)
66 throw std::domain_error(fmt::format(
67 "secp384r1 key cannot be used with COSE algorithm {}", cose_alg));
70 else if (gname == SN_secp521r1)
74 throw std::domain_error(fmt::format(
75 "secp521r1 key cannot be used with COSE algorithm {}", cose_alg));
80 throw std::domain_error(
81 fmt::format(
"Unsupported EC curve: {}", gname));
84 else if (key_type == EVP_PKEY_RSA || key_type == EVP_PKEY_RSA_PSS)
91 if (cose_alg != -37 && cose_alg != -38 && cose_alg != -39)
93 throw std::domain_error(
94 fmt::format(
"Incompatible cose algorithm {} for RSA", cose_alg));
99 throw std::domain_error(
100 fmt::format(
"Unsupported key type {}", key_type));