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

Side by Side Diff: public/platform/WebCryptoAlgorithmParams.h

Issue 109393003: [webcrypto] Refactor some of the algorithm parameter names. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Improve a comment Created 7 years 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 | « Source/modules/crypto/RsaKeyGenParams.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 24 matching lines...) Expand all
35 #include "WebCryptoAlgorithm.h" 35 #include "WebCryptoAlgorithm.h"
36 #include "WebVector.h" 36 #include "WebVector.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 // NOTE: For documentation on the meaning of each of the parameters see the 40 // NOTE: For documentation on the meaning of each of the parameters see the
41 // Web crypto spec: 41 // Web crypto spec:
42 // 42 //
43 // http://www.w3.org/TR/WebCryptoAPI 43 // http://www.w3.org/TR/WebCryptoAPI
44 // 44 //
45 // The parameters in the spec have the same name, minus the "WebCrypto" pr efix. 45 // For the most part, the parameters in the spec have the same name,
46 // except that in the blink code:
47 //
48 // - Structure names are prefixed by "WebCrypto"
49 // - Optional fields are prefixed by "optional"
50 // - Data length properties are suffixed by either "Bits" or "Bytes"
46 51
47 class WebCryptoAlgorithmParams { 52 class WebCryptoAlgorithmParams {
48 public: 53 public:
49 explicit WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsType type) 54 explicit WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsType type)
50 : m_type(type) 55 : m_type(type)
51 { 56 {
52 } 57 }
53 58
54 virtual ~WebCryptoAlgorithmParams() { } 59 virtual ~WebCryptoAlgorithmParams() { }
55 60
(...skipping 12 matching lines...) Expand all
68 } 73 }
69 74
70 const WebVector<unsigned char>& iv() const { return m_iv; } 75 const WebVector<unsigned char>& iv() const { return m_iv; }
71 76
72 private: 77 private:
73 const WebVector<unsigned char> m_iv; 78 const WebVector<unsigned char> m_iv;
74 }; 79 };
75 80
76 class WebCryptoAesCtrParams : public WebCryptoAlgorithmParams { 81 class WebCryptoAesCtrParams : public WebCryptoAlgorithmParams {
77 public: 82 public:
78 WebCryptoAesCtrParams(unsigned char length, const unsigned char* counter, un signed counterSize) 83 WebCryptoAesCtrParams(unsigned char lengthBits, const unsigned char* counter , unsigned counterSize)
79 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesCtrParams) 84 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesCtrParams)
80 , m_counter(counter, counterSize) 85 , m_counter(counter, counterSize)
81 , m_length(length) 86 , m_lengthBits(lengthBits)
82 { 87 {
83 } 88 }
84 89
85 const WebVector<unsigned char>& counter() const { return m_counter; } 90 const WebVector<unsigned char>& counter() const { return m_counter; }
86 unsigned char length() const { return m_length; } 91 unsigned char lengthBits() const { return m_lengthBits; }
87 92
88 private: 93 private:
89 const WebVector<unsigned char> m_counter; 94 const WebVector<unsigned char> m_counter;
90 const unsigned char m_length; 95 const unsigned char m_lengthBits;
91 }; 96 };
92 97
93 class WebCryptoAesKeyGenParams : public WebCryptoAlgorithmParams { 98 class WebCryptoAesKeyGenParams : public WebCryptoAlgorithmParams {
94 public: 99 public:
95 explicit WebCryptoAesKeyGenParams(unsigned short length) 100 explicit WebCryptoAesKeyGenParams(unsigned short lengthBits)
96 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesKeyGenParams) 101 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesKeyGenParams)
97 , m_length(length) 102 , m_lengthBits(lengthBits)
98 { 103 {
99 } 104 }
100 105
101 unsigned short length() const { return m_length; } 106 // FIXME: Delete once no longer referenced by chromium.
107 unsigned short length() const { return m_lengthBits; }
108
109 unsigned short lengthBits() const { return m_lengthBits; }
102 110
103 private: 111 private:
104 const unsigned short m_length; 112 const unsigned short m_lengthBits;
105 }; 113 };
106 114
107 class WebCryptoHmacParams : public WebCryptoAlgorithmParams { 115 class WebCryptoHmacParams : public WebCryptoAlgorithmParams {
108 public: 116 public:
109 explicit WebCryptoHmacParams(const WebCryptoAlgorithm& hash) 117 explicit WebCryptoHmacParams(const WebCryptoAlgorithm& hash)
110 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeHmacParams) 118 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeHmacParams)
111 , m_hash(hash) 119 , m_hash(hash)
112 { 120 {
113 BLINK_ASSERT(!hash.isNull()); 121 BLINK_ASSERT(!hash.isNull());
114 } 122 }
115 123
116 const WebCryptoAlgorithm& hash() const { return m_hash; } 124 const WebCryptoAlgorithm& hash() const { return m_hash; }
117 125
118 private: 126 private:
119 const WebCryptoAlgorithm m_hash; 127 const WebCryptoAlgorithm m_hash;
120 }; 128 };
121 129
122 class WebCryptoHmacKeyParams : public WebCryptoAlgorithmParams { 130 class WebCryptoHmacKeyParams : public WebCryptoAlgorithmParams {
123 public: 131 public:
124 WebCryptoHmacKeyParams(const WebCryptoAlgorithm& hash, bool hasLength, unsig ned length) 132 WebCryptoHmacKeyParams(const WebCryptoAlgorithm& hash, bool hasLengthBytes, unsigned lengthBytes)
125 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeHmacKeyParams) 133 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeHmacKeyParams)
126 , m_hash(hash) 134 , m_hash(hash)
127 , m_hasLength(hasLength) 135 , m_hasLengthBytes(hasLengthBytes)
128 , m_length(length) 136 , m_optionalLengthBytes(lengthBytes)
129 { 137 {
130 BLINK_ASSERT(!hash.isNull()); 138 BLINK_ASSERT(!hash.isNull());
139 BLINK_ASSERT(hasLengthBytes || !lengthBytes);
131 } 140 }
132 141
133 const WebCryptoAlgorithm& hash() const { return m_hash; } 142 const WebCryptoAlgorithm& hash() const { return m_hash; }
134 143
135 bool hasLength() const { return m_hasLength; } 144 bool hasLengthBytes() const { return m_hasLengthBytes; }
136 145
146 // FIXME: Delete once no longer referenced by chromium.
137 bool getLength(unsigned& length) const 147 bool getLength(unsigned& length) const
138 { 148 {
139 if (!m_hasLength) 149 if (!m_hasLengthBytes)
140 return false; 150 return false;
141 length = m_length; 151 length = m_optionalLengthBytes;
142 return true; 152 return true;
143 } 153 }
144 154
155 unsigned optionalLengthBytes() const { return m_optionalLengthBytes; }
156
145 private: 157 private:
146 const WebCryptoAlgorithm m_hash; 158 const WebCryptoAlgorithm m_hash;
147 const bool m_hasLength; 159 const bool m_hasLengthBytes;
148 const unsigned m_length; 160 const unsigned m_optionalLengthBytes;
149 }; 161 };
150 162
151 class WebCryptoRsaSsaParams : public WebCryptoAlgorithmParams { 163 class WebCryptoRsaSsaParams : public WebCryptoAlgorithmParams {
152 public: 164 public:
153 explicit WebCryptoRsaSsaParams(const WebCryptoAlgorithm& hash) 165 explicit WebCryptoRsaSsaParams(const WebCryptoAlgorithm& hash)
154 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaSsaParams) 166 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaSsaParams)
155 , m_hash(hash) 167 , m_hash(hash)
156 { 168 {
157 BLINK_ASSERT(!hash.isNull()); 169 BLINK_ASSERT(!hash.isNull());
158 } 170 }
159 171
160 const WebCryptoAlgorithm& hash() const { return m_hash; } 172 const WebCryptoAlgorithm& hash() const { return m_hash; }
161 173
162 private: 174 private:
163 const WebCryptoAlgorithm m_hash; 175 const WebCryptoAlgorithm m_hash;
164 }; 176 };
165 177
166 class WebCryptoRsaKeyGenParams : public WebCryptoAlgorithmParams { 178 class WebCryptoRsaKeyGenParams : public WebCryptoAlgorithmParams {
167 public: 179 public:
168 WebCryptoRsaKeyGenParams(unsigned modulusLength, const unsigned char* public Exponent, unsigned publicExponentSize) 180 WebCryptoRsaKeyGenParams(unsigned modulusLengthBits, const unsigned char* pu blicExponent, unsigned publicExponentSize)
169 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaKeyGenParams) 181 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaKeyGenParams)
170 , m_modulusLength(modulusLength) 182 , m_modulusLengthBits(modulusLengthBits)
171 , m_publicExponent(publicExponent, publicExponentSize) 183 , m_publicExponent(publicExponent, publicExponentSize)
172 { 184 {
173 } 185 }
174 186
175 unsigned modulusLength() const { return m_modulusLength; } 187 // FIXME: Delete once no longer referenced by chromium.
188 unsigned modulusLength() const { return m_modulusLengthBits; }
189
190 unsigned modulusLengthBits() const { return m_modulusLengthBits; }
176 const WebVector<unsigned char>& publicExponent() const { return m_publicExpo nent; } 191 const WebVector<unsigned char>& publicExponent() const { return m_publicExpo nent; }
177 192
178 private: 193 private:
179 const unsigned m_modulusLength; 194 const unsigned m_modulusLengthBits;
180 const WebVector<unsigned char> m_publicExponent; 195 const WebVector<unsigned char> m_publicExponent;
181 }; 196 };
182 197
183 class WebCryptoAesGcmParams : public WebCryptoAlgorithmParams { 198 class WebCryptoAesGcmParams : public WebCryptoAlgorithmParams {
184 public: 199 public:
185 WebCryptoAesGcmParams(const unsigned char* iv, unsigned ivSize, bool hasAddi tionalData, const unsigned char* additionalData, unsigned additionalDataSize, bo ol hasTagLength, unsigned char tagLength) 200 WebCryptoAesGcmParams(const unsigned char* iv, unsigned ivSize, bool hasAddi tionalData, const unsigned char* additionalData, unsigned additionalDataSize, bo ol hasTagLengthBits, unsigned char tagLengthBits)
186 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesGcmParams) 201 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesGcmParams)
187 , m_iv(iv, ivSize) 202 , m_iv(iv, ivSize)
188 , m_hasAdditionalData(hasAdditionalData) 203 , m_hasAdditionalData(hasAdditionalData)
189 , m_additionalData(additionalData, additionalDataSize) 204 , m_optionalAdditionalData(additionalData, additionalDataSize)
190 , m_hasTagLength(hasTagLength) 205 , m_hasTagLengthBits(hasTagLengthBits)
191 , m_tagLength(tagLength) 206 , m_optionalTagLengthBits(tagLengthBits)
192 { 207 {
208 BLINK_ASSERT(hasAdditionalData || !additionalDataSize);
209 BLINK_ASSERT(hasTagLengthBits || !tagLengthBits);
193 } 210 }
194 211
195 const WebVector<unsigned char>& iv() const { return m_iv; } 212 const WebVector<unsigned char>& iv() const { return m_iv; }
196 213
197 bool hasAdditionalData() const { return m_hasAdditionalData; } 214 bool hasAdditionalData() const { return m_hasAdditionalData; }
198 bool getAdditionalData(const WebVector<unsigned char>*& additionalData) cons t 215 const WebVector<unsigned char>& optionalAdditionalData() const { return m_op tionalAdditionalData; }
199 {
200 if (!m_hasAdditionalData)
201 return false;
202 additionalData = &m_additionalData;
203 return true;
204 }
205 216
206 bool hasTagLength() const { return m_hasTagLength; } 217 bool hasTagLengthBits() const { return m_hasTagLengthBits; }
207 bool getTagLength(unsigned& tagLength) const 218 unsigned optionalTagLengthBits() const { return m_optionalTagLengthBits; }
208 {
209 if (!m_hasTagLength)
210 return false;
211 tagLength = m_tagLength;
212 return true;
213 }
214 219
215 private: 220 private:
216 const WebVector<unsigned char> m_iv; 221 const WebVector<unsigned char> m_iv;
217 const bool m_hasAdditionalData; 222 const bool m_hasAdditionalData;
218 const WebVector<unsigned char> m_additionalData; 223 const WebVector<unsigned char> m_optionalAdditionalData;
219 const bool m_hasTagLength; 224 const bool m_hasTagLengthBits;
220 const unsigned char m_tagLength; 225 const unsigned char m_optionalTagLengthBits;
221 }; 226 };
222 227
223 class WebCryptoRsaOaepParams : public WebCryptoAlgorithmParams { 228 class WebCryptoRsaOaepParams : public WebCryptoAlgorithmParams {
224 public: 229 public:
225 WebCryptoRsaOaepParams(const WebCryptoAlgorithm& hash, bool hasLabel, const unsigned char* label, unsigned labelSize) 230 WebCryptoRsaOaepParams(const WebCryptoAlgorithm& hash, bool hasLabel, const unsigned char* label, unsigned labelSize)
226 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaOaepParams) 231 : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaOaepParams)
227 , m_hash(hash) 232 , m_hash(hash)
228 , m_hasLabel(hasLabel) 233 , m_hasLabel(hasLabel)
229 , m_label(label, labelSize) 234 , m_optionalLabel(label, labelSize)
230 { 235 {
231 BLINK_ASSERT(!hash.isNull()); 236 BLINK_ASSERT(!hash.isNull());
237 BLINK_ASSERT(hasLabel || !labelSize);
232 } 238 }
233 239
234 const WebCryptoAlgorithm& hash() const { return m_hash; } 240 const WebCryptoAlgorithm& hash() const { return m_hash; }
235 241
236 bool hasLabel() const { return m_hasLabel; } 242 bool hasLabel() const { return m_hasLabel; }
237 bool getLabel(const WebVector<unsigned char>*& label) const 243 const WebVector<unsigned char>& optionalLabel() const { return m_optionalLab el; }
238 {
239 if (!m_hasLabel)
240 return false;
241 label = &m_label;
242 return true;
243 }
244 244
245 private: 245 private:
246 const WebCryptoAlgorithm m_hash; 246 const WebCryptoAlgorithm m_hash;
247 const bool m_hasLabel; 247 const bool m_hasLabel;
248 const WebVector<unsigned char> m_label; 248 const WebVector<unsigned char> m_optionalLabel;
249 }; 249 };
250 250
251 } // namespace blink 251 } // namespace blink
252 252
253 #endif 253 #endif
OLDNEW
« no previous file with comments | « Source/modules/crypto/RsaKeyGenParams.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698