#include "components/webcrypto/jwk.h"
#include <stddef.h>
#include <algorithm>
#include <optional>
#include <set>
#include <utility>
#include "base/base64url.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "components/webcrypto/algorithms/util.h"
#include "components/webcrypto/status.h"
namespace webcrypto {
namespace {
const blink::WebCryptoKeyUsageMask kJwkEncUsage = …;
const blink::WebCryptoKeyUsageMask kJwkSigUsage = …;
Status VerifyExt(const JwkReader& jwk, bool expected_extractable) { … }
struct JwkToWebCryptoUsageMapping { … };
const JwkToWebCryptoUsageMapping kJwkWebCryptoUsageMap[] = …;
bool JwkKeyOpToWebCryptoUsage(std::string_view key_op,
blink::WebCryptoKeyUsage* usage) { … }
base::Value::List CreateJwkKeyOpsFromWebCryptoUsages(
blink::WebCryptoKeyUsageMask usages) { … }
Status GetWebCryptoUsagesFromJwkKeyOps(const base::Value::List& key_ops,
blink::WebCryptoKeyUsageMask* usages) { … }
Status VerifyUsages(const JwkReader& jwk,
blink::WebCryptoKeyUsageMask expected_usages) { … }
}
JwkReader::JwkReader() = default;
JwkReader::~JwkReader() = default;
Status JwkReader::Init(base::span<const uint8_t> bytes,
bool expected_extractable,
blink::WebCryptoKeyUsageMask expected_usages,
std::string_view expected_kty,
std::string_view expected_alg) { … }
bool JwkReader::HasMember(std::string_view member_name) const { … }
Status JwkReader::GetString(std::string_view member_name,
std::string* result) const { … }
Status JwkReader::GetOptionalString(std::string_view member_name,
std::string* result,
bool* member_exists) const { … }
Status JwkReader::GetOptionalList(std::string_view member_name,
const base::Value::List** result,
bool* member_exists) const { … }
Status JwkReader::GetBytes(std::string_view member_name,
std::vector<uint8_t>* result) const { … }
Status JwkReader::GetBigInteger(std::string_view member_name,
std::vector<uint8_t>* result) const { … }
Status JwkReader::GetOptionalBool(std::string_view member_name,
bool* result,
bool* member_exists) const { … }
Status JwkReader::GetAlg(std::string* alg, bool* has_alg) const { … }
Status JwkReader::VerifyAlg(std::string_view expected_alg) const { … }
JwkWriter::JwkWriter(std::string_view algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
std::string_view kty) { … }
void JwkWriter::SetString(std::string_view member_name,
std::string_view value) { … }
void JwkWriter::SetBytes(std::string_view member_name,
base::span<const uint8_t> value) { … }
void JwkWriter::ToJson(std::vector<uint8_t>* utf8_bytes) const { … }
Status GetWebCryptoUsagesFromJwkKeyOpsForTest(
const base::Value::List& key_ops,
blink::WebCryptoKeyUsageMask* usages) { … }
}