OLD | NEW |
| (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_WEBCRYPTO_IMPL_H_ | |
6 #define CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_IMPL_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "third_party/WebKit/public/platform/WebCrypto.h" | |
11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | |
12 #include "third_party/WebKit/public/platform/WebVector.h" | |
13 | |
14 namespace content { | |
15 | |
16 // Wrapper around the Blink WebCrypto asynchronous interface, which forwards to | |
17 // the synchronous platform (NSS or OpenSSL) implementation. | |
18 // | |
19 // WebCryptoImpl is threadsafe. | |
20 // | |
21 // EnsureInit() must be called prior to using methods on WebCryptoImpl(). | |
22 class WebCryptoImpl : public blink::WebCrypto { | |
23 public: | |
24 WebCryptoImpl(); | |
25 | |
26 // TODO(eroman): Once Blink and Chromium repositories are merged, use | |
27 // "override" in place of virtual. | |
28 | |
29 virtual ~WebCryptoImpl(); | |
30 | |
31 virtual void encrypt(const blink::WebCryptoAlgorithm& algorithm, | |
32 const blink::WebCryptoKey& key, | |
33 const unsigned char* data, | |
34 unsigned int data_size, | |
35 blink::WebCryptoResult result); | |
36 virtual void decrypt(const blink::WebCryptoAlgorithm& algorithm, | |
37 const blink::WebCryptoKey& key, | |
38 const unsigned char* data, | |
39 unsigned int data_size, | |
40 blink::WebCryptoResult result); | |
41 virtual void digest(const blink::WebCryptoAlgorithm& algorithm, | |
42 const unsigned char* data, | |
43 unsigned int data_size, | |
44 blink::WebCryptoResult result); | |
45 virtual void generateKey(const blink::WebCryptoAlgorithm& algorithm, | |
46 bool extractable, | |
47 blink::WebCryptoKeyUsageMask usages, | |
48 blink::WebCryptoResult result); | |
49 virtual void importKey(blink::WebCryptoKeyFormat format, | |
50 const unsigned char* key_data, | |
51 unsigned int key_data_size, | |
52 const blink::WebCryptoAlgorithm& algorithm, | |
53 bool extractable, | |
54 blink::WebCryptoKeyUsageMask usages, | |
55 blink::WebCryptoResult result); | |
56 virtual void exportKey(blink::WebCryptoKeyFormat format, | |
57 const blink::WebCryptoKey& key, | |
58 blink::WebCryptoResult result); | |
59 virtual void sign(const blink::WebCryptoAlgorithm& algorithm, | |
60 const blink::WebCryptoKey& key, | |
61 const unsigned char* data, | |
62 unsigned int data_size, | |
63 blink::WebCryptoResult result); | |
64 virtual void verifySignature(const blink::WebCryptoAlgorithm& algorithm, | |
65 const blink::WebCryptoKey& key, | |
66 const unsigned char* signature, | |
67 unsigned int signature_size, | |
68 const unsigned char* data, | |
69 unsigned int data_size, | |
70 blink::WebCryptoResult result); | |
71 virtual void wrapKey(blink::WebCryptoKeyFormat format, | |
72 const blink::WebCryptoKey& key, | |
73 const blink::WebCryptoKey& wrapping_key, | |
74 const blink::WebCryptoAlgorithm& wrap_algorithm, | |
75 blink::WebCryptoResult result); | |
76 virtual void unwrapKey( | |
77 blink::WebCryptoKeyFormat format, | |
78 const unsigned char* wrapped_key, | |
79 unsigned wrapped_key_size, | |
80 const blink::WebCryptoKey& wrapping_key, | |
81 const blink::WebCryptoAlgorithm& unwrap_algorithm, | |
82 const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, | |
83 bool extractable, | |
84 blink::WebCryptoKeyUsageMask usages, | |
85 blink::WebCryptoResult result); | |
86 | |
87 virtual void deriveBits(const blink::WebCryptoAlgorithm& algorithm, | |
88 const blink::WebCryptoKey& base_key, | |
89 unsigned int length_bits, | |
90 blink::WebCryptoResult result); | |
91 | |
92 virtual void deriveKey(const blink::WebCryptoAlgorithm& algorithm, | |
93 const blink::WebCryptoKey& base_key, | |
94 const blink::WebCryptoAlgorithm& import_algorithm, | |
95 const blink::WebCryptoAlgorithm& key_length_algorithm, | |
96 bool extractable, | |
97 blink::WebCryptoKeyUsageMask usages, | |
98 blink::WebCryptoResult result); | |
99 | |
100 // This method returns a digestor object that can be used to synchronously | |
101 // compute a digest one chunk at a time. Thus, the consume does not need to | |
102 // hold onto a large buffer with all the data to digest. Chunks can be given | |
103 // one at a time and the digest will be computed piecemeal. The allocated | |
104 // WebCrytpoDigestor that is returned by createDigestor must be freed by the | |
105 // caller. | |
106 virtual blink::WebCryptoDigestor* createDigestor( | |
107 blink::WebCryptoAlgorithmId algorithm_id); | |
108 | |
109 virtual bool deserializeKeyForClone( | |
110 const blink::WebCryptoKeyAlgorithm& algorithm, | |
111 blink::WebCryptoKeyType type, | |
112 bool extractable, | |
113 blink::WebCryptoKeyUsageMask usages, | |
114 const unsigned char* key_data, | |
115 unsigned key_data_size, | |
116 blink::WebCryptoKey& key); | |
117 | |
118 virtual bool serializeKeyForClone(const blink::WebCryptoKey& key, | |
119 blink::WebVector<unsigned char>& key_data); | |
120 | |
121 private: | |
122 DISALLOW_COPY_AND_ASSIGN(WebCryptoImpl); | |
123 }; | |
124 | |
125 } // namespace content | |
126 | |
127 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_IMPL_H_ | |
OLD | NEW |