OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "public/platform/WebCryptoAlgorithm.h" | 31 #include "public/platform/WebCryptoAlgorithm.h" |
32 | 32 |
33 #include "public/platform/WebCryptoAlgorithmParams.h" | 33 #include "public/platform/WebCryptoAlgorithmParams.h" |
34 #include "wtf/Assertions.h" | 34 #include "wtf/Assertions.h" |
35 #include "wtf/PtrUtil.h" | 35 #include "wtf/OwnPtr.h" |
36 #include "wtf/StdLibExtras.h" | 36 #include "wtf/StdLibExtras.h" |
37 #include "wtf/ThreadSafeRefCounted.h" | 37 #include "wtf/ThreadSafeRefCounted.h" |
38 #include <memory> | |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 // A mapping from the algorithm ID to information about the algorithm. | 43 // A mapping from the algorithm ID to information about the algorithm. |
45 const WebCryptoAlgorithmInfo algorithmIdToInfo[] = { | 44 const WebCryptoAlgorithmInfo algorithmIdToInfo[] = { |
46 { // Index 0 | 45 { // Index 0 |
47 "AES-CBC", { | 46 "AES-CBC", { |
48 WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt | 47 WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match"); | 288 static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match"); |
290 static_assert(WebCryptoAlgorithmIdHkdf == 14, "HKDF id must match"); | 289 static_assert(WebCryptoAlgorithmIdHkdf == 14, "HKDF id must match"); |
291 static_assert(WebCryptoAlgorithmIdPbkdf2 == 15, "Pbkdf2 id must match"); | 290 static_assert(WebCryptoAlgorithmIdPbkdf2 == 15, "Pbkdf2 id must match"); |
292 static_assert(WebCryptoAlgorithmIdLast == 15, "last id must match"); | 291 static_assert(WebCryptoAlgorithmIdLast == 15, "last id must match"); |
293 static_assert(10 == WebCryptoOperationLast, "the parameter mapping needs to be u
pdated"); | 292 static_assert(10 == WebCryptoOperationLast, "the parameter mapping needs to be u
pdated"); |
294 | 293 |
295 } // namespace | 294 } // namespace |
296 | 295 |
297 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm
Private> { | 296 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm
Private> { |
298 public: | 297 public: |
299 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, std::unique_ptr<WebCrypto
AlgorithmParams> params) | 298 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor
ithmParams> params) |
300 : id(id) | 299 : id(id) |
301 , params(std::move(params)) | 300 , params(std::move(params)) |
302 { | 301 { |
303 } | 302 } |
304 | 303 |
305 WebCryptoAlgorithmId id; | 304 WebCryptoAlgorithmId id; |
306 std::unique_ptr<WebCryptoAlgorithmParams> params; | 305 OwnPtr<WebCryptoAlgorithmParams> params; |
307 }; | 306 }; |
308 | 307 |
309 WebCryptoAlgorithm::WebCryptoAlgorithm(WebCryptoAlgorithmId id, std::unique_ptr<
WebCryptoAlgorithmParams> params) | 308 WebCryptoAlgorithm::WebCryptoAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr<WebCr
yptoAlgorithmParams> params) |
310 : m_private(adoptRef(new WebCryptoAlgorithmPrivate(id, std::move(params)))) | 309 : m_private(adoptRef(new WebCryptoAlgorithmPrivate(id, std::move(params)))) |
311 { | 310 { |
312 } | 311 } |
313 | 312 |
314 WebCryptoAlgorithm WebCryptoAlgorithm::createNull() | 313 WebCryptoAlgorithm WebCryptoAlgorithm::createNull() |
315 { | 314 { |
316 return WebCryptoAlgorithm(); | 315 return WebCryptoAlgorithm(); |
317 } | 316 } |
318 | 317 |
319 WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId
id, WebCryptoAlgorithmParams* params) | 318 WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId
id, WebCryptoAlgorithmParams* params) |
320 { | 319 { |
321 return WebCryptoAlgorithm(id, wrapUnique(params)); | 320 return WebCryptoAlgorithm(id, adoptPtr(params)); |
322 } | 321 } |
323 | 322 |
324 const WebCryptoAlgorithmInfo* WebCryptoAlgorithm::lookupAlgorithmInfo(WebCryptoA
lgorithmId id) | 323 const WebCryptoAlgorithmInfo* WebCryptoAlgorithm::lookupAlgorithmInfo(WebCryptoA
lgorithmId id) |
325 { | 324 { |
326 const unsigned idInt = id; | 325 const unsigned idInt = id; |
327 if (idInt >= WTF_ARRAY_LENGTH(algorithmIdToInfo)) | 326 if (idInt >= WTF_ARRAY_LENGTH(algorithmIdToInfo)) |
328 return 0; | 327 return 0; |
329 return &algorithmIdToInfo[id]; | 328 return &algorithmIdToInfo[id]; |
330 } | 329 } |
331 | 330 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 { | 537 { |
539 m_private = other.m_private; | 538 m_private = other.m_private; |
540 } | 539 } |
541 | 540 |
542 void WebCryptoAlgorithm::reset() | 541 void WebCryptoAlgorithm::reset() |
543 { | 542 { |
544 m_private.reset(); | 543 m_private.reset(); |
545 } | 544 } |
546 | 545 |
547 } // namespace blink | 546 } // namespace blink |
OLD | NEW |