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