#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/crypto/normalize_algorithm.h"
#include <algorithm>
#include <memory>
#include <string>
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/bindings/core/v8/dictionary.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_object_string.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_crypto_key.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_piece.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/crypto/crypto_key.h"
#include "third_party/blink/renderer/modules/crypto/crypto_utilities.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
namespace {
struct AlgorithmNameMapping { … };
const AlgorithmNameMapping kAlgorithmNameMappings[] = …;
static_assert …;
#if DCHECK_IS_ON()
template <typename Iterator>
bool IsSorted(Iterator begin, Iterator end) { … }
bool AlgorithmNameMapping::operator<(const AlgorithmNameMapping& o) const { … }
bool VerifyAlgorithmNameMappings(const AlgorithmNameMapping* begin,
const AlgorithmNameMapping* end) { … }
#endif
template <typename CharType>
bool AlgorithmNameComparator(const AlgorithmNameMapping& a, StringImpl* b) { … }
bool LookupAlgorithmIdByName(const String& algorithm_name,
WebCryptoAlgorithmId& id) { … }
void SetTypeError(const String& message, ExceptionState& exception_state) { … }
void SetNotSupportedError(const String& message,
ExceptionState& exception_state) { … }
class ErrorContext { … };
bool GetOptionalBufferSource(const Dictionary& raw,
const char* property_name,
bool& has_property,
WebVector<uint8_t>& bytes,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetBufferSource(const Dictionary& raw,
const char* property_name,
WebVector<uint8_t>& bytes,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetUint8Array(const Dictionary& raw,
const char* property_name,
WebVector<uint8_t>& bytes,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetBigInteger(const Dictionary& raw,
const char* property_name,
WebVector<uint8_t>& bytes,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetOptionalInteger(const Dictionary& raw,
const char* property_name,
bool& has_property,
double& value,
double min_value,
double max_value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetInteger(const Dictionary& raw,
const char* property_name,
double& value,
double min_value,
double max_value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetUint32(const Dictionary& raw,
const char* property_name,
uint32_t& value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetUint16(const Dictionary& raw,
const char* property_name,
uint16_t& value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetUint8(const Dictionary& raw,
const char* property_name,
uint8_t& value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetOptionalUint32(const Dictionary& raw,
const char* property_name,
bool& has_value,
uint32_t& value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetOptionalUint8(const Dictionary& raw,
const char* property_name,
bool& has_value,
uint8_t& value,
const ErrorContext& context,
ExceptionState& exception_state) { … }
V8AlgorithmIdentifier* GetAlgorithmIdentifier(v8::Isolate* isolate,
const Dictionary& raw,
const char* property_name,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAesCbcParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAesKeyGenParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAlgorithmIdentifier(v8::Isolate*,
const V8AlgorithmIdentifier&,
WebCryptoOperation,
WebCryptoAlgorithm&,
ErrorContext,
ExceptionState&);
bool ParseHash(v8::Isolate* isolate,
const Dictionary& raw,
WebCryptoAlgorithm& hash,
ErrorContext context,
ExceptionState& exception_state) { … }
bool ParseHmacImportParams(v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseHmacKeyGenParams(v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseRsaHashedImportParams(
v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseRsaHashedKeyGenParams(
v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAesCtrParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAesGcmParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseRsaOaepParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseRsaPssParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseEcdsaParams(v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
struct CurveNameMapping { … };
const CurveNameMapping kCurveNameMappings[] = …;
static_assert …;
bool ParseNamedCurve(const Dictionary& raw,
WebCryptoNamedCurve& named_curve,
ErrorContext context,
ExceptionState& exception_state) { … }
bool ParseEcKeyGenParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseEcKeyImportParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool GetPeerPublicKey(const Dictionary& raw,
const ErrorContext& context,
WebCryptoKey* peer_public_key,
ExceptionState& exception_state) { … }
bool ParseEcdhKeyDeriveParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParsePbkdf2Params(v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAesDerivedKeyParams(const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseHkdfParams(v8::Isolate* isolate,
const Dictionary& raw,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
const ErrorContext& context,
ExceptionState& exception_state) { … }
bool ParseAlgorithmParams(v8::Isolate* isolate,
const Dictionary& raw,
WebCryptoAlgorithmParamsType type,
std::unique_ptr<WebCryptoAlgorithmParams>& params,
ErrorContext& context,
ExceptionState& exception_state) { … }
const char* OperationToString(WebCryptoOperation op) { … }
bool ParseAlgorithmDictionary(v8::Isolate* isolate,
const String& algorithm_name,
const Dictionary& raw,
WebCryptoOperation op,
WebCryptoAlgorithm& algorithm,
ErrorContext context,
ExceptionState& exception_state) { … }
bool ParseAlgorithmIdentifier(v8::Isolate* isolate,
const V8AlgorithmIdentifier& raw,
WebCryptoOperation op,
WebCryptoAlgorithm& algorithm,
ErrorContext context,
ExceptionState& exception_state) { … }
}
bool NormalizeAlgorithm(v8::Isolate* isolate,
const V8AlgorithmIdentifier* raw,
WebCryptoOperation op,
WebCryptoAlgorithm& algorithm,
ExceptionState& exception_state) { … }
}