Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / child / webcrypto / webcrypto_util.h
blobbbacc9b4d6627b750b529ff02284675f342fe29f
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_
6 #define CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_
8 #include <stdint.h>
9 #include <string>
11 #include "base/values.h"
12 #include "content/common/content_export.h"
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
14 #include "third_party/WebKit/public/platform/WebCryptoKey.h"
16 namespace content {
18 namespace webcrypto {
20 class Status;
22 // Composes a Web Crypto usage mask from an array of JWK key_ops values.
23 CONTENT_EXPORT Status GetWebCryptoUsagesFromJwkKeyOps(
24 const base::ListValue* jwk_key_ops_value,
25 blink::WebCryptoKeyUsageMask* jwk_key_ops_mask);
27 // Composes a JWK key_ops array from a Web Crypto usage mask.
28 base::ListValue* CreateJwkKeyOpsFromWebCryptoUsages(
29 blink::WebCryptoKeyUsageMask usage_mask);
31 // Creates a WebCryptoAlgorithm without any parameters.
32 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateAlgorithm(
33 blink::WebCryptoAlgorithmId id);
35 // Creates an HMAC import algorithm whose inner hash algorithm is determined by
36 // the specified algorithm ID. It is an error to call this method with a hash
37 // algorithm that is not SHA*.
38 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateHmacImportAlgorithm(
39 blink::WebCryptoAlgorithmId hash_id);
41 // Creates an import algorithm for RSA algorithms that take a hash.
42 // It is an error to call this with a hash_id that is not a SHA*.
43 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm(
44 blink::WebCryptoAlgorithmId id,
45 blink::WebCryptoAlgorithmId hash_id);
47 // Returns true if the set bits in b make up a subset of the set bits in a.
48 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a,
49 blink::WebCryptoKeyUsageMask b);
51 bool KeyUsageAllows(const blink::WebCryptoKey& key,
52 const blink::WebCryptoKeyUsage usage);
54 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id);
55 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id);
57 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params,
58 unsigned int* tag_length_bits);
60 Status GetAesKeyGenLengthInBits(const blink::WebCryptoAesKeyGenParams* params,
61 unsigned int* keylen_bits);
63 Status GetHmacKeyGenLengthInBits(const blink::WebCryptoHmacKeyGenParams* params,
64 unsigned int* keylen_bits);
66 Status VerifyAesKeyLengthForImport(unsigned int keylen_bytes);
68 Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages,
69 blink::WebCryptoKeyUsageMask actual_usages);
71 // Extracts the public exponent and modulus length from the Blink parameters.
72 // On success it is guaranteed that:
73 // * public_exponent is either 3 or 65537
74 // * modulus_length_bits is a multiple of 8
75 // * modulus_length is >= 256
76 // * modulus_length is <= 16K
77 Status GetRsaKeyGenParameters(
78 const blink::WebCryptoRsaHashedKeyGenParams* params,
79 unsigned int* public_exponent,
80 unsigned int* modulus_length_bits);
82 } // namespace webcrypto
84 } // namespace content
86 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_