OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_WEBCRYPTO_ALGORITHM_IMPLEMENTATION_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_ALGORITHM_IMPLEMENTATION_H_ |
6 #define CONTENT_CHILD_WEBCRYPTO_ALGORITHM_IMPLEMENTATION_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_ALGORITHM_IMPLEMENTATION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "third_party/WebKit/public/platform/WebCrypto.h" | 12 #include "third_party/WebKit/public/platform/WebCrypto.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace webcrypto { | 16 namespace webcrypto { |
17 | 17 |
18 class CryptoData; | 18 class CryptoData; |
| 19 class GenerateKeyResult; |
19 class Status; | 20 class Status; |
20 | 21 |
21 // AlgorithmImplementation is a base class for *executing* the operations of an | 22 // AlgorithmImplementation is a base class for *executing* the operations of an |
22 // algorithm (generating keys, encrypting, signing, etc.). | 23 // algorithm (generating keys, encrypting, signing, etc.). |
23 // | 24 // |
24 // This is in contrast to blink::WebCryptoAlgorithm which instead *describes* | 25 // This is in contrast to blink::WebCryptoAlgorithm which instead *describes* |
25 // the operation and its parameters. | 26 // the operation and its parameters. |
26 // | 27 // |
27 // AlgorithmImplementation has reasonable default implementations for all | 28 // AlgorithmImplementation has reasonable default implementations for all |
28 // methods which behave as if the operation is it is unsupported, so | 29 // methods which behave as if the operation is it is unsupported, so |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const blink::WebCryptoKey& key, | 65 const blink::WebCryptoKey& key, |
65 const CryptoData& signature, | 66 const CryptoData& signature, |
66 const CryptoData& data, | 67 const CryptoData& data, |
67 bool* signature_match) const; | 68 bool* signature_match) const; |
68 | 69 |
69 // This method corresponds to Web Crypto's crypto.subtle.digest(). | 70 // This method corresponds to Web Crypto's crypto.subtle.digest(). |
70 virtual Status Digest(const blink::WebCryptoAlgorithm& algorithm, | 71 virtual Status Digest(const blink::WebCryptoAlgorithm& algorithm, |
71 const CryptoData& data, | 72 const CryptoData& data, |
72 std::vector<uint8_t>* buffer) const; | 73 std::vector<uint8_t>* buffer) const; |
73 | 74 |
74 // VerifyKeyUsagesBeforeGenerateKey() must be called prior to | |
75 // GenerateSecretKey() to validate the requested key usages. | |
76 virtual Status VerifyKeyUsagesBeforeGenerateKey( | |
77 blink::WebCryptoKeyUsageMask usage_mask) const; | |
78 | |
79 // This method corresponds to Web Crypto's crypto.subtle.generateKey(). | 75 // This method corresponds to Web Crypto's crypto.subtle.generateKey(). |
80 virtual Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm, | 76 // |
81 bool extractable, | 77 // Implementations MUST verify |usage_mask| and return an error if it is not |
82 blink::WebCryptoKeyUsageMask usage_mask, | 78 // appropriate. |
83 blink::WebCryptoKey* key) const; | 79 virtual Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
84 | 80 bool extractable, |
85 // VerifyKeyUsagesBeforeGenerateKeyPair() must be called prior to | 81 blink::WebCryptoKeyUsageMask usage_mask, |
86 // GenerateKeyPair() to validate the requested key usages. | 82 GenerateKeyResult* result) const; |
87 virtual Status VerifyKeyUsagesBeforeGenerateKeyPair( | |
88 blink::WebCryptoKeyUsageMask combined_usage_mask, | |
89 blink::WebCryptoKeyUsageMask* public_usage_mask, | |
90 blink::WebCryptoKeyUsageMask* private_usage_mask) const; | |
91 | |
92 // This method corresponds to Web Crypto's crypto.subtle.generateKey(). | |
93 virtual Status GenerateKeyPair( | |
94 const blink::WebCryptoAlgorithm& algorithm, | |
95 bool extractable, | |
96 blink::WebCryptoKeyUsageMask public_usage_mask, | |
97 blink::WebCryptoKeyUsageMask private_usage_mask, | |
98 blink::WebCryptoKey* public_key, | |
99 blink::WebCryptoKey* private_key) const; | |
100 | 83 |
101 // ----------------------------------------------- | 84 // ----------------------------------------------- |
102 // Key import | 85 // Key import |
103 // ----------------------------------------------- | 86 // ----------------------------------------------- |
104 | 87 |
105 // VerifyKeyUsagesBeforeImportKey() must be called before either | 88 // VerifyKeyUsagesBeforeImportKey() must be called before either |
106 // importing a key, or unwrapping a key. | 89 // importing a key, or unwrapping a key. |
107 // | 90 // |
108 // Implementations should return an error if the requested usages are invalid | 91 // Implementations should return an error if the requested usages are invalid |
109 // when importing for the specified format. | 92 // when importing for the specified format. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 148 |
166 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key, | 149 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key, |
167 std::vector<uint8_t>* buffer) const; | 150 std::vector<uint8_t>* buffer) const; |
168 }; | 151 }; |
169 | 152 |
170 } // namespace webcrypto | 153 } // namespace webcrypto |
171 | 154 |
172 } // namespace content | 155 } // namespace content |
173 | 156 |
174 #endif // CONTENT_CHILD_WEBCRYPTO_ALGORITHM_IMPLEMENTATION_H_ | 157 #endif // CONTENT_CHILD_WEBCRYPTO_ALGORITHM_IMPLEMENTATION_H_ |
OLD | NEW |