ExtensionInstallDialogView: fix scrolling behavior on Views (Win,Linux)
[chromium-blink-merge.git] / components / webcrypto / algorithm_dispatch.h
blobdeac6ded45e6e328c2d13503dd888e5fe4578c8e
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 COMPONENTS_WEBCRYPTO_ALGORITHM_DISPATCH_H_
6 #define COMPONENTS_WEBCRYPTO_ALGORITHM_DISPATCH_H_
8 #include <stdint.h>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/WebKit/public/platform/WebCrypto.h"
14 namespace webcrypto {
16 class AlgorithmImplementation;
17 class CryptoData;
18 class GenerateKeyResult;
19 class Status;
21 // These functions provide an entry point for synchronous webcrypto operations.
23 // The inputs to these methods come from Blink, and hence the validations done
24 // by Blink can be assumed:
26 // * The algorithm parameters are consistent with the algorithm
27 // * The key contains the required usage for the operation
29 Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
30 const blink::WebCryptoKey& key,
31 const CryptoData& data,
32 std::vector<uint8_t>* buffer);
34 Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
35 const blink::WebCryptoKey& key,
36 const CryptoData& data,
37 std::vector<uint8_t>* buffer);
39 Status Digest(const blink::WebCryptoAlgorithm& algorithm,
40 const CryptoData& data,
41 std::vector<uint8_t>* buffer);
43 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
44 bool extractable,
45 blink::WebCryptoKeyUsageMask usages,
46 GenerateKeyResult* result);
48 Status ImportKey(blink::WebCryptoKeyFormat format,
49 const CryptoData& key_data,
50 const blink::WebCryptoAlgorithm& algorithm,
51 bool extractable,
52 blink::WebCryptoKeyUsageMask usages,
53 blink::WebCryptoKey* key);
55 Status ExportKey(blink::WebCryptoKeyFormat format,
56 const blink::WebCryptoKey& key,
57 std::vector<uint8_t>* buffer);
59 Status Sign(const blink::WebCryptoAlgorithm& algorithm,
60 const blink::WebCryptoKey& key,
61 const CryptoData& data,
62 std::vector<uint8_t>* buffer);
64 Status Verify(const blink::WebCryptoAlgorithm& algorithm,
65 const blink::WebCryptoKey& key,
66 const CryptoData& signature,
67 const CryptoData& data,
68 bool* signature_match);
70 Status WrapKey(blink::WebCryptoKeyFormat format,
71 const blink::WebCryptoKey& key_to_wrap,
72 const blink::WebCryptoKey& wrapping_key,
73 const blink::WebCryptoAlgorithm& wrapping_algorithm,
74 std::vector<uint8_t>* buffer);
76 Status UnwrapKey(blink::WebCryptoKeyFormat format,
77 const CryptoData& wrapped_key_data,
78 const blink::WebCryptoKey& wrapping_key,
79 const blink::WebCryptoAlgorithm& wrapping_algorithm,
80 const blink::WebCryptoAlgorithm& algorithm,
81 bool extractable,
82 blink::WebCryptoKeyUsageMask usages,
83 blink::WebCryptoKey* key);
85 Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm,
86 const blink::WebCryptoKey& base_key,
87 unsigned int length_bits,
88 std::vector<uint8_t>* derived_bytes);
90 // Derives a key by calling the underlying deriveBits/getKeyLength/importKey
91 // operations.
93 // Note that whereas the WebCrypto spec uses a single "derivedKeyType"
94 // AlgorithmIdentifier in its specification of deriveKey(), here two separate
95 // AlgorithmIdentifiers are used:
97 // * |import_algorithm| -- The parameters required by the derived key's
98 // "importKey" operation.
100 // * |key_length_algorithm| -- The parameters required by the derived key's
101 // "get key length" operation.
103 // WebCryptoAlgorithm is not a flexible type like AlgorithmIdentifier (it cannot
104 // be easily re-interpreted as a different parameter type).
106 // Therefore being provided with separate parameter types for the import
107 // parameters and the key length parameters simplifies passing the right
108 // parameters onto ImportKey() and GetKeyLength() respectively.
109 Status DeriveKey(const blink::WebCryptoAlgorithm& algorithm,
110 const blink::WebCryptoKey& base_key,
111 const blink::WebCryptoAlgorithm& import_algorithm,
112 const blink::WebCryptoAlgorithm& key_length_algorithm,
113 bool extractable,
114 blink::WebCryptoKeyUsageMask usages,
115 blink::WebCryptoKey* derived_key);
117 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
118 blink::WebCryptoAlgorithmId algorithm);
120 bool SerializeKeyForClone(const blink::WebCryptoKey& key,
121 blink::WebVector<uint8_t>* key_data);
123 bool DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
124 blink::WebCryptoKeyType type,
125 bool extractable,
126 blink::WebCryptoKeyUsageMask usages,
127 const CryptoData& key_data,
128 blink::WebCryptoKey* key);
130 } // namespace webcrypto
132 #endif // COMPONENTS_WEBCRYPTO_ALGORITHM_DISPATCH_H_