- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / webcrypto / webcrypto_impl.h
1 // Copyright (c) 2013 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_RENDERER_WEBCRYPTO_WEBCRYPTO_IMPL_H_
6 #define CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_IMPL_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "content/common/content_export.h"
11 #include "third_party/WebKit/public/platform/WebCrypto.h"
12
13 namespace content {
14
15 class CONTENT_EXPORT WebCryptoImpl
16     : NON_EXPORTED_BASE(public WebKit::WebCrypto) {
17  public:
18   WebCryptoImpl();
19
20   virtual void encrypt(
21       const WebKit::WebCryptoAlgorithm& algorithm,
22       const WebKit::WebCryptoKey& key,
23       const unsigned char* data,
24       unsigned data_size,
25       WebKit::WebCryptoResult result);
26   virtual void decrypt(
27       const WebKit::WebCryptoAlgorithm& algorithm,
28       const WebKit::WebCryptoKey& key,
29       const unsigned char* data,
30       unsigned data_size,
31       WebKit::WebCryptoResult result);
32   virtual void digest(
33       const WebKit::WebCryptoAlgorithm& algorithm,
34       const unsigned char* data,
35       unsigned data_size,
36       WebKit::WebCryptoResult result);
37   virtual void generateKey(
38       const WebKit::WebCryptoAlgorithm& algorithm,
39       bool extractable,
40       WebKit::WebCryptoKeyUsageMask usage_mask,
41       WebKit::WebCryptoResult result);
42   virtual void importKey(
43       WebKit::WebCryptoKeyFormat format,
44       const unsigned char* key_data,
45       unsigned key_data_size,
46       const WebKit::WebCryptoAlgorithm& algorithm_or_null,
47       bool extractable,
48       WebKit::WebCryptoKeyUsageMask usage_mask,
49       WebKit::WebCryptoResult result);
50   virtual void sign(
51       const WebKit::WebCryptoAlgorithm& algorithm,
52       const WebKit::WebCryptoKey& key,
53       const unsigned char* data,
54       unsigned data_size,
55       WebKit::WebCryptoResult result);
56   virtual void verifySignature(
57       const WebKit::WebCryptoAlgorithm& algorithm,
58       const WebKit::WebCryptoKey& key,
59       const unsigned char* signature,
60       unsigned signature_size,
61       const unsigned char* data,
62       unsigned data_size,
63       WebKit::WebCryptoResult result);
64
65   static void ShrinkBuffer(WebKit::WebArrayBuffer* buffer, unsigned new_size);
66   static WebKit::WebCryptoKey NullKey();
67
68  protected:
69   friend class WebCryptoImplTest;
70
71   void Init();
72
73   bool EncryptInternal(
74       const WebKit::WebCryptoAlgorithm& algorithm,
75       const WebKit::WebCryptoKey& key,
76       const unsigned char* data,
77       unsigned data_size,
78       WebKit::WebArrayBuffer* buffer);
79   bool DecryptInternal(
80       const WebKit::WebCryptoAlgorithm& algorithm,
81       const WebKit::WebCryptoKey& key,
82       const unsigned char* data,
83       unsigned data_size,
84       WebKit::WebArrayBuffer* buffer);
85   bool DigestInternal(
86       const WebKit::WebCryptoAlgorithm& algorithm,
87       const unsigned char* data,
88       unsigned data_size,
89       WebKit::WebArrayBuffer* buffer);
90   bool GenerateKeyInternal(
91       const WebKit::WebCryptoAlgorithm& algorithm,
92       bool extractable,
93       WebKit::WebCryptoKeyUsageMask usage_mask,
94       WebKit::WebCryptoKey* key);
95   bool GenerateKeyPairInternal(
96       const WebKit::WebCryptoAlgorithm& algorithm,
97       bool extractable,
98       WebKit::WebCryptoKeyUsageMask usage_mask,
99       WebKit::WebCryptoKey* public_key,
100       WebKit::WebCryptoKey* private_key);
101   bool ImportKeyInternal(
102       WebKit::WebCryptoKeyFormat format,
103       const unsigned char* key_data,
104       unsigned key_data_size,
105       const WebKit::WebCryptoAlgorithm& algorithm_or_null,
106       bool extractable,
107       WebKit::WebCryptoKeyUsageMask usage_mask,
108       WebKit::WebCryptoKey* key);
109   bool SignInternal(
110       const WebKit::WebCryptoAlgorithm& algorithm,
111       const WebKit::WebCryptoKey& key,
112       const unsigned char* data,
113       unsigned data_size,
114       WebKit::WebArrayBuffer* buffer);
115   bool VerifySignatureInternal(
116       const WebKit::WebCryptoAlgorithm& algorithm,
117       const WebKit::WebCryptoKey& key,
118       const unsigned char* signature,
119       unsigned signature_size,
120       const unsigned char* data,
121       unsigned data_size,
122       bool* signature_match);
123
124  private:
125   DISALLOW_COPY_AND_ASSIGN(WebCryptoImpl);
126 };
127
128 }  // namespace content
129
130 #endif  // CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_IMPL_H_