Commit 15170bb8 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

Expose WebCrypto's lookupAlgorithmInfo.

Will allow reuse of this function in the implementation of the enterprise.platfromKeys Chrome extension API.

BUG=364435

Review URL: https://codereview.chromium.org/312393004

git-svn-id: svn://svn.chromium.org/blink/trunk@176190 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 063b2a76
......@@ -36,6 +36,7 @@
#include "modules/crypto/NormalizeAlgorithm.h"
#include "modules/crypto/RsaHashedKeyAlgorithm.h"
#include "modules/crypto/RsaKeyAlgorithm.h"
#include "public/platform/WebCryptoAlgorithm.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
......@@ -75,7 +76,8 @@ KeyAlgorithm::KeyAlgorithm(const blink::WebCryptoKeyAlgorithm& algorithm)
String KeyAlgorithm::name()
{
return algorithmIdToName(m_algorithm.id());
const blink::WebCryptoAlgorithmInfo* info = blink::WebCryptoAlgorithm::lookupAlgorithmInfo(m_algorithm.id());
return info->name;
}
bool KeyAlgorithm::isAesKeyAlgorithm() const
......
......@@ -75,194 +75,6 @@ const AlgorithmNameMapping algorithmNameMappings[] = {
{"RSASSA-PKCS1-V1_5", 17, blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5},
};
typedef char ParamsTypeOrUndefined;
const ParamsTypeOrUndefined Undefined = -1;
struct AlgorithmInfo {
// The canonical (case-sensitive) name for the algorithm.
const char* name;
// A map from the operation to the expected parameter type of the algorithm.
// If an operation is not applicable for the algorithm, set to Undefined.
const ParamsTypeOrUndefined operationToParamsType[blink::WebCryptoOperationLast + 1];
};
// A mapping from the algorithm ID to information about the algorithm.
const AlgorithmInfo algorithmIdToInfo[] = {
{ // Index 0
"AES-CBC", {
blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt
blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // Decrypt
Undefined, // Sign
Undefined, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // WrapKey
blink::WebCryptoAlgorithmParamsTypeAesCbcParams // UnwrapKey
}
}, { // Index 1
"HMAC", {
Undefined, // Encrypt
Undefined, // Decrypt
blink::WebCryptoAlgorithmParamsTypeNone, // Sign
blink::WebCryptoAlgorithmParamsTypeNone, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeHmacImportParams, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
Undefined, // WrapKey
Undefined // UnwrapKey
}
}, { // Index 2
"RSASSA-PKCS1-v1_5", {
Undefined, // Encrypt
Undefined, // Decrypt
blink::WebCryptoAlgorithmParamsTypeNone, // Sign
blink::WebCryptoAlgorithmParamsTypeNone, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
Undefined, // WrapKey
Undefined // UnwrapKey
}
}, { // Index 3
"SHA-1", {
Undefined, // Encrypt
Undefined, // Decrypt
Undefined, // Sign
Undefined, // Verify
blink::WebCryptoAlgorithmParamsTypeNone, // Digest
Undefined, // GenerateKey
Undefined, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
Undefined, // WrapKey
Undefined // UnwrapKey
}
}, { // Index 4
"SHA-256", {
Undefined, // Encrypt
Undefined, // Decrypt
Undefined, // Sign
Undefined, // Verify
blink::WebCryptoAlgorithmParamsTypeNone, // Digest
Undefined, // GenerateKey
Undefined, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
Undefined, // WrapKey
Undefined // UnwrapKey
}
}, { // Index 5
"SHA-384", {
Undefined, // Encrypt
Undefined, // Decrypt
Undefined, // Sign
Undefined, // Verify
blink::WebCryptoAlgorithmParamsTypeNone, // Digest
Undefined, // GenerateKey
Undefined, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
Undefined, // WrapKey
Undefined // UnwrapKey
}
}, { // Index 6
"SHA-512", {
Undefined, // Encrypt
Undefined, // Decrypt
Undefined, // Sign
Undefined, // Verify
blink::WebCryptoAlgorithmParamsTypeNone, // Digest
Undefined, // GenerateKey
Undefined, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
Undefined, // WrapKey
Undefined // UnwrapKey
}
}, { // Index 7
"AES-GCM", {
blink::WebCryptoAlgorithmParamsTypeAesGcmParams, // Encrypt
blink::WebCryptoAlgorithmParamsTypeAesGcmParams, // Decrypt
Undefined, // Sign
Undefined, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
blink::WebCryptoAlgorithmParamsTypeAesGcmParams, // WrapKey
blink::WebCryptoAlgorithmParamsTypeAesGcmParams // UnwrapKey
}
}, { // Index 8
"RSA-OAEP", {
blink::WebCryptoAlgorithmParamsTypeRsaOaepParams, // Encrypt
blink::WebCryptoAlgorithmParamsTypeRsaOaepParams, // Decrypt
Undefined, // Sign
Undefined, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
blink::WebCryptoAlgorithmParamsTypeRsaOaepParams, // WrapKey
blink::WebCryptoAlgorithmParamsTypeRsaOaepParams // UnwrapKey
}
}, { // Index 9
"AES-CTR", {
blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // Encrypt
blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // Decrypt
Undefined, // Sign
Undefined, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
blink::WebCryptoAlgorithmParamsTypeAesCtrParams, // WrapKey
blink::WebCryptoAlgorithmParamsTypeAesCtrParams // UnwrapKey
}
}, { // Index 10
"AES-KW", {
Undefined, // Encrypt
Undefined, // Decrypt
Undefined, // Sign
Undefined, // Verify
Undefined, // Digest
blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
blink::WebCryptoAlgorithmParamsTypeNone, // ImportKey
Undefined, // DeriveKey
Undefined, // DeriveBits
blink::WebCryptoAlgorithmParamsTypeNone, // WrapKey
blink::WebCryptoAlgorithmParamsTypeNone // UnwrapKey
}
},
};
// Initializing the algorithmIdToInfo table above depends on knowing the enum
// values for algorithm IDs. If those ever change, the table will need to be
// updated.
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesCbc == 0, AesCbc_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdHmac == 1, Hmac_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2, RsaSsaPkcs1v1_5_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha1 == 3, Sha1_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha256 == 4, Sha256_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha384 == 5, Sha384_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha512 == 6, Sha512_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesGcm == 7, AesGcm_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdRsaOaep == 8, RsaOaep_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesCtr == 9, AesCtr_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesKw == 10, AesKw_idDoesntMatch);
COMPILE_ASSERT(blink::WebCryptoAlgorithmIdLast == 10, Last_idDoesntMatch);
COMPILE_ASSERT(10 == blink::WebCryptoOperationLast, UpdateParamsMapping);
#if ASSERT_ENABLED
// Essentially std::is_sorted() (however that function is new to C++11).
......@@ -372,13 +184,6 @@ bool lookupAlgorithmIdByName(const String& algorithmName, blink::WebCryptoAlgori
return true;
}
const AlgorithmInfo* lookupAlgorithmInfo(blink::WebCryptoAlgorithmId id)
{
if (id < 0 || id >= WTF_ARRAY_LENGTH(algorithmIdToInfo))
return 0;
return &algorithmIdToInfo[id];
}
void setSyntaxError(const String& message, AlgorithmError* error)
{
error->errorType = blink::WebCryptoErrorTypeSyntax;
......@@ -896,10 +701,10 @@ bool parseAlgorithm(const Dictionary& raw, blink::WebCryptoOperation op, blink::
// Remove the "Algorithm:" prefix for all subsequent errors.
context.removeLast();
const AlgorithmInfo* algorithmInfo = lookupAlgorithmInfo(algorithmId);
const blink::WebCryptoAlgorithmInfo* algorithmInfo = blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithmId);
if (algorithmInfo->operationToParamsType[op] == Undefined) {
context.add(algorithmIdToName(algorithmId));
if (algorithmInfo->operationToParamsType[op] == blink::WebCryptoAlgorithmInfo::Undefined) {
context.add(algorithmInfo->name);
setNotSupportedError(context.toString("Unsupported operation", operationToString(op)), error);
return false;
}
......@@ -921,9 +726,4 @@ bool normalizeAlgorithm(const Dictionary& raw, blink::WebCryptoOperation op, bli
return parseAlgorithm(raw, op, algorithm, ErrorContext(), error);
}
const char* algorithmIdToName(blink::WebCryptoAlgorithmId id)
{
return lookupAlgorithmInfo(id)->name;
}
} // namespace WebCore
......@@ -37,8 +37,6 @@
#include "wtf/Assertions.h"
#include "wtf/Forward.h"
namespace blink { class WebCryptoAlgorithm; }
namespace WebCore {
class Dictionary;
......@@ -61,10 +59,6 @@ struct AlgorithmError {
// [1] http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules
bool normalizeAlgorithm(const Dictionary&, blink::WebCryptoOperation, blink::WebCryptoAlgorithm&, AlgorithmError*) WARN_UNUSED_RETURN;
// Returns a null-terminated C-string literal. Caller can assume the pointer
// will be valid for the program's entire runtime.
const char* algorithmIdToName(blink::WebCryptoAlgorithmId);
} // namespace WebCore
#endif
......@@ -32,11 +32,193 @@
#include "public/platform/WebCryptoAlgorithm.h"
#include "public/platform/WebCryptoAlgorithmParams.h"
#include "wtf/Assertions.h"
#include "wtf/OwnPtr.h"
#include "wtf/StdLibExtras.h"
#include "wtf/ThreadSafeRefCounted.h"
namespace blink {
namespace {
// A mapping from the algorithm ID to information about the algorithm.
const WebCryptoAlgorithmInfo algorithmIdToInfo[] = {
{ // Index 0
"AES-CBC", {
WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt
WebCryptoAlgorithmParamsTypeAesCbcParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeAesCbcParams, // WrapKey
WebCryptoAlgorithmParamsTypeAesCbcParams // UnwrapKey
}
}, { // Index 1
"HMAC", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmParamsTypeNone, // Sign
WebCryptoAlgorithmParamsTypeNone, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeHmacKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeHmacImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}
}, { // Index 2
"RSASSA-PKCS1-v1_5", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmParamsTypeNone, // Sign
WebCryptoAlgorithmParamsTypeNone, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}
}, { // Index 3
"SHA-1", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}
}, { // Index 4
"SHA-256", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}
}, { // Index 5
"SHA-384", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}
}, { // Index 6
"SHA-512", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}
}, { // Index 7
"AES-GCM", {
WebCryptoAlgorithmParamsTypeAesGcmParams, // Encrypt
WebCryptoAlgorithmParamsTypeAesGcmParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeAesGcmParams, // WrapKey
WebCryptoAlgorithmParamsTypeAesGcmParams // UnwrapKey
}
}, { // Index 8
"RSA-OAEP", {
WebCryptoAlgorithmParamsTypeRsaOaepParams, // Encrypt
WebCryptoAlgorithmParamsTypeRsaOaepParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeRsaOaepParams, // WrapKey
WebCryptoAlgorithmParamsTypeRsaOaepParams // UnwrapKey
}
}, { // Index 9
"AES-CTR", {
WebCryptoAlgorithmParamsTypeAesCtrParams, // Encrypt
WebCryptoAlgorithmParamsTypeAesCtrParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeAesCtrParams, // WrapKey
WebCryptoAlgorithmParamsTypeAesCtrParams // UnwrapKey
}
}, { // Index 10
"AES-KW", {
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // DeriveKey
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeNone, // WrapKey
WebCryptoAlgorithmParamsTypeNone // UnwrapKey
}
},
};
// Initializing the algorithmIdToInfo table above depends on knowing the enum
// values for algorithm IDs. If those ever change, the table will need to be
// updated.
COMPILE_ASSERT(WebCryptoAlgorithmIdAesCbc == 0, AesCbc_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdHmac == 1, Hmac_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2, RsaSsaPkcs1v1_5_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdSha1 == 3, Sha1_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdSha256 == 4, Sha256_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdSha384 == 5, Sha384_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdSha512 == 6, Sha512_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdAesGcm == 7, AesGcm_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdRsaOaep == 8, RsaOaep_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdAesCtr == 9, AesCtr_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdAesKw == 10, AesKw_idDoesntMatch);
COMPILE_ASSERT(WebCryptoAlgorithmIdLast == 10, Last_idDoesntMatch);
COMPILE_ASSERT(10 == WebCryptoOperationLast, UpdateParamsMapping);
} // namespace
class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithmPrivate> {
public:
WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgorithmParams> params)
......@@ -64,6 +246,13 @@ WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId
return WebCryptoAlgorithm(id, adoptPtr(params));
}
const WebCryptoAlgorithmInfo* WebCryptoAlgorithm::lookupAlgorithmInfo(WebCryptoAlgorithmId id)
{
if (id < 0 || id >= WTF_ARRAY_LENGTH(algorithmIdToInfo))
return 0;
return &algorithmIdToInfo[id];
}
bool WebCryptoAlgorithm::isNull() const
{
return m_private.isNull();
......
......@@ -85,6 +85,20 @@ enum WebCryptoAlgorithmParamsType {
WebCryptoAlgorithmParamsTypeAesCtrParams,
};
struct WebCryptoAlgorithmInfo {
typedef char ParamsTypeOrUndefined;
static const ParamsTypeOrUndefined Undefined = -1;
// The canonical (case-sensitive) name for the algorithm as a
// null-terminated C-string literal.
const char* name;
// A map from the operation to the expected parameter type of the algorithm.
// If an operation is not applicable for the algorithm, set to Undefined.
const ParamsTypeOrUndefined operationToParamsType[WebCryptoOperationLast + 1];
};
class WebCryptoAesCbcParams;
class WebCryptoAesKeyGenParams;
class WebCryptoHmacImportParams;
......@@ -115,6 +129,11 @@ public:
BLINK_PLATFORM_EXPORT static WebCryptoAlgorithm createNull();
BLINK_PLATFORM_EXPORT static WebCryptoAlgorithm adoptParamsAndCreate(WebCryptoAlgorithmId, WebCryptoAlgorithmParams*);
// Returns a WebCryptoAlgorithmInfo for the algorithm with the given ID. If
// the ID is invalid, return 0. The caller can assume the pointer will be
// valid for the program's entire runtime.
BLINK_PLATFORM_EXPORT static const WebCryptoAlgorithmInfo* lookupAlgorithmInfo(WebCryptoAlgorithmId);
~WebCryptoAlgorithm() { reset(); }
WebCryptoAlgorithm(const WebCryptoAlgorithm& other) { assign(other); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment