Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/child/webcrypto/algorithm.h

Issue 379383002: Refactor WebCrypto code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add #include<vector> Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/child/blink_platform_impl.cc ('k') | content/child/webcrypto/algorithm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CONTENT_CHILD_WEBCRYPTO_CRYPTO_ALGORITHM_H_
6 #define CONTENT_CHILD_WEBCRYPTO_CRYPTO_ALGORITHM_H_
Ryan Sleevi 2014/07/12 00:55:28 This file should be ALGORITHM_IMPLEMENTATION_H / A
7
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "third_party/WebKit/public/platform/WebCrypto.h"
12
13 namespace content {
14
15 namespace webcrypto {
16
17 class CryptoData;
18 class Status;
19
20 // AlgorithmImplementation is a base class for *executing* the operations of an
21 // algorithm (generating keys, encrypting, signing, etc.).
22 //
23 // This is in contrast to blink::WebCryptoAlgorithm which instead *describes*
24 // the operation and its parameters.
25 //
26 // AlgorithmImplementation has reasonable default implementations for all
27 // methods which behave as if the operation is it is unsupported, so
28 // implementations need only override the applicable methods.
29 //
30 // Unless stated otherwise methods of AlgorithmImplementation are responsible
31 // for sanitizing their inputs. The following can be assumed:
32 //
33 // * |algorithm.id()| and |key.algorithm.id()| matches the algorithm under
34 // which the implementation was registerd.
35 // * |algorithm| has the correct parameters type for the operation.
36 // * The key usages have already been verified. In fact in the case of calls
37 // to Encrypt()/Decrypt() the corresponding key usages may not be present
38 // (when wrapping/unwrapping).
39 class AlgorithmImplementation {
40 public:
41 virtual ~AlgorithmImplementation();
42
43 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
44 const blink::WebCryptoKey& key,
45 const CryptoData& data,
46 std::vector<uint8>* buffer) const;
47
48 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
49 const blink::WebCryptoKey& key,
50 const CryptoData& data,
51 std::vector<uint8>* buffer) const;
52
53 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm,
54 const blink::WebCryptoKey& key,
55 const CryptoData& data,
56 std::vector<uint8>* buffer) const;
57
58 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm,
59 const blink::WebCryptoKey& key,
60 const CryptoData& signature,
61 const CryptoData& data,
62 bool* signature_match) const;
63
64 virtual Status Digest(const blink::WebCryptoAlgorithm& algorithm,
65 const CryptoData& data,
66 std::vector<uint8>* buffer) const;
67
68 // When generating a key, VerifyKeyUsagesVeforeGenerateKey() will always be
69 // called before GenerateSecretKey(). Similarly when generating a keypair
70 // VerifyKeyUsagesBeforeGenerateKey() will always be called before
71 // GenerateKeyPair().
72
73 virtual Status VerifyKeyUsagesBeforeGenerateKey(
74 blink::WebCryptoKeyUsageMask usage_mask) const;
75
76 virtual Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm,
77 bool extractable,
78 blink::WebCryptoKeyUsageMask usage_mask,
79 blink::WebCryptoKey* key) const;
80
81 virtual Status VerifyKeyUsagesBeforeGenerateKeyPair(
82 blink::WebCryptoKeyUsageMask combined_usage_mask,
83 blink::WebCryptoKeyUsageMask* public_usage_mask,
84 blink::WebCryptoKeyUsageMask* private_usage_mask) const;
85
86 virtual Status GenerateKeyPair(
87 const blink::WebCryptoAlgorithm& algorithm,
88 bool extractable,
89 blink::WebCryptoKeyUsageMask public_usage_mask,
90 blink::WebCryptoKeyUsageMask private_usage_mask,
91 blink::WebCryptoKey* public_key,
92 blink::WebCryptoKey* private_key) const;
93
94 // -----------------------------------------------
95 // Key import
96 // -----------------------------------------------
97 // VerifyKeyUsagesBeforeImportKey() will always be called before either
98 // importing a key, or unwrapping a key.
99 //
100 // Note that when the format is JWK and importing an asymmetric key,
101 // VerifyKeyUsagesBeforeImportKey() will not know what the key type is yet. In
102 // this case the import function will be responsible for checking the usage.
103
104 virtual Status VerifyKeyUsagesBeforeImportKey(
105 blink::WebCryptoKeyFormat format,
106 blink::WebCryptoKeyUsageMask usage_mask) const;
107
108 virtual Status ImportKeyRaw(const CryptoData& key_data,
109 const blink::WebCryptoAlgorithm& algorithm,
110 bool extractable,
111 blink::WebCryptoKeyUsageMask usage_mask,
112 blink::WebCryptoKey* key) const;
113
114 virtual Status ImportKeyPkcs8(const CryptoData& key_data,
115 const blink::WebCryptoAlgorithm& algorithm,
116 bool extractable,
117 blink::WebCryptoKeyUsageMask usage_mask,
118 blink::WebCryptoKey* key) const;
119
120 virtual Status ImportKeySpki(const CryptoData& key_data,
121 const blink::WebCryptoAlgorithm& algorithm,
122 bool extractable,
123 blink::WebCryptoKeyUsageMask usage_mask,
124 blink::WebCryptoKey* key) const;
125
126 virtual Status ImportKeyJwk(const CryptoData& key_data,
127 const blink::WebCryptoAlgorithm& algorithm,
128 bool extractable,
129 blink::WebCryptoKeyUsageMask usage_mask,
130 blink::WebCryptoKey* key) const;
131
132 // -----------------------------------------------
133 // Key export
134 // -----------------------------------------------
135
136 virtual Status ExportKeyRaw(const blink::WebCryptoKey& key,
137 std::vector<uint8>* buffer) const;
138
139 virtual Status ExportKeyPkcs8(const blink::WebCryptoKey& key,
140 std::vector<uint8>* buffer) const;
141
142 virtual Status ExportKeySpki(const blink::WebCryptoKey& key,
143 std::vector<uint8>* buffer) const;
144
145 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key,
146 std::vector<uint8>* buffer) const;
147 };
148
149 } // namespace webcrypto
150
151 } // namespace content
152
153 #endif // CONTENT_CHILD_WEBCRYPTO_CRYPTO_ALGORITHM_H_
OLDNEW
« no previous file with comments | « content/child/blink_platform_impl.cc ('k') | content/child/webcrypto/algorithm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698