OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef WebCryptoAlgorithmParams_h | |
32 #define WebCryptoAlgorithmParams_h | |
33 | |
34 #include "WebCommon.h" | |
35 #include "WebCryptoAlgorithm.h" | |
36 | |
37 namespace WebKit { | |
38 | |
39 // Base class for all the algorithm parameters. | |
40 // | |
41 // NOTE: For documentation on the meaning of each of the parameters see the Web | |
42 // Crypto spec. Parameters have the same name (minus "WebCrypto" prefix). | |
abarth-chromium
2013/07/02 06:46:36
Please add a link to the spec.
eroman
2013/07/02 08:12:27
Done.
| |
43 class WebCryptoAlgorithmParams { | |
44 public: | |
45 WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsType type) | |
46 : m_type(type) | |
47 { | |
48 } | |
49 | |
50 virtual ~WebCryptoAlgorithmParams() { } | |
51 | |
52 WebCryptoAlgorithmParamsType type() const { return m_type; } | |
53 | |
54 protected: | |
55 // Helper class for a chunk of owned immutable data. | |
abarth-chromium
2013/07/02 06:46:36
We should be able to just use WebVector
eroman
2013/07/02 08:12:27
Done.
| |
56 class Bytes { | |
57 public: | |
58 // Makes a copy of |data|. | |
59 Bytes(const unsigned char*, size_t); | |
60 ~Bytes(); | |
61 | |
62 const unsigned char* data() const { return m_data; } | |
63 size_t size() const { return m_size; } | |
64 | |
65 private: | |
66 Bytes(const Bytes&); | |
67 Bytes& operator=(const Bytes&); | |
68 | |
69 const unsigned char* m_data; | |
70 size_t m_size; | |
71 }; | |
72 | |
73 private: | |
74 WebCryptoAlgorithmParamsType m_type; | |
75 }; | |
76 | |
77 class WebCryptoAesCbcParams : public WebCryptoAlgorithmParams { | |
78 public: | |
79 WebCryptoAesCbcParams(unsigned char* iv, size_t ivSize) | |
80 : WebCryptoAlgorithmParams(AesCbcParams) | |
81 , m_iv(iv, ivSize) | |
82 { | |
83 } | |
84 | |
85 // The initialization vector. MUST be 16 bytes. | |
abarth-chromium
2013/07/02 06:46:36
Can you enforce that with an ASSERT rather than a
eroman
2013/07/02 08:12:27
Removed the comment.
I had copy-pasted it from th
| |
86 const unsigned char* iv() const { return m_iv.data(); } | |
87 size_t ivSize() const { return m_iv.size(); } | |
88 | |
89 private: | |
90 const Bytes m_iv; | |
91 }; | |
92 | |
93 class WebCryptoAesKeyGenParams : public WebCryptoAlgorithmParams { | |
94 public: | |
95 WebCryptoAesKeyGenParams(unsigned short length) | |
96 : WebCryptoAlgorithmParams(AesKeyGenParams) | |
97 , m_length(length) | |
98 { | |
99 } | |
100 | |
101 // The length, in bits, of the key. | |
102 unsigned short length() const { return m_length; } | |
103 | |
104 private: | |
105 const unsigned short m_length; | |
106 }; | |
107 | |
108 } // namespace WebKit | |
109 | |
110 #endif | |
OLD | NEW |