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

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebCryptoKeyAlgorithm.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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/WebCryptoKeyAlgorithm.h" 31 #include "public/platform/WebCryptoKeyAlgorithm.h"
32 32
33 #include "wtf/OwnPtr.h" 33 #include "wtf/PtrUtil.h"
34 #include "wtf/ThreadSafeRefCounted.h" 34 #include "wtf/ThreadSafeRefCounted.h"
35 #include <memory>
35 36
36 namespace blink { 37 namespace blink {
37 38
38 // FIXME: Remove the need for this. 39 // FIXME: Remove the need for this.
39 WebCryptoAlgorithm createHash(WebCryptoAlgorithmId hash) 40 WebCryptoAlgorithm createHash(WebCryptoAlgorithmId hash)
40 { 41 {
41 return WebCryptoAlgorithm::adoptParamsAndCreate(hash, 0); 42 return WebCryptoAlgorithm::adoptParamsAndCreate(hash, 0);
42 } 43 }
43 44
44 class WebCryptoKeyAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoKeyAlg orithmPrivate> { 45 class WebCryptoKeyAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoKeyAlg orithmPrivate> {
45 public: 46 public:
46 WebCryptoKeyAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoKe yAlgorithmParams> params) 47 WebCryptoKeyAlgorithmPrivate(WebCryptoAlgorithmId id, std::unique_ptr<WebCry ptoKeyAlgorithmParams> params)
47 : id(id) 48 : id(id)
48 , params(std::move(params)) 49 , params(std::move(params))
49 { 50 {
50 } 51 }
51 52
52 WebCryptoAlgorithmId id; 53 WebCryptoAlgorithmId id;
53 OwnPtr<WebCryptoKeyAlgorithmParams> params; 54 std::unique_ptr<WebCryptoKeyAlgorithmParams> params;
54 }; 55 };
55 56
56 WebCryptoKeyAlgorithm::WebCryptoKeyAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr <WebCryptoKeyAlgorithmParams> params) 57 WebCryptoKeyAlgorithm::WebCryptoKeyAlgorithm(WebCryptoAlgorithmId id, std::uniqu e_ptr<WebCryptoKeyAlgorithmParams> params)
57 : m_private(adoptRef(new WebCryptoKeyAlgorithmPrivate(id, std::move(params)) )) 58 : m_private(adoptRef(new WebCryptoKeyAlgorithmPrivate(id, std::move(params)) ))
58 { 59 {
59 } 60 }
60 61
61 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::adoptParamsAndCreate(WebCryptoAlgor ithmId id, WebCryptoKeyAlgorithmParams* params) 62 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::adoptParamsAndCreate(WebCryptoAlgor ithmId id, WebCryptoKeyAlgorithmParams* params)
62 { 63 {
63 return WebCryptoKeyAlgorithm(id, adoptPtr(params)); 64 return WebCryptoKeyAlgorithm(id, wrapUnique(params));
64 } 65 }
65 66
66 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createAes(WebCryptoAlgorithmId id, unsigned short keyLengthBits) 67 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createAes(WebCryptoAlgorithmId id, unsigned short keyLengthBits)
67 { 68 {
68 // FIXME: Verify that id is an AES algorithm. 69 // FIXME: Verify that id is an AES algorithm.
69 // FIXME: Move this somewhere more general. 70 // FIXME: Move this somewhere more general.
70 if (keyLengthBits != 128 && keyLengthBits != 192 && keyLengthBits != 256) 71 if (keyLengthBits != 128 && keyLengthBits != 192 && keyLengthBits != 256)
71 return WebCryptoKeyAlgorithm(); 72 return WebCryptoKeyAlgorithm();
72 return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoAesKeyAlgorithmParams (keyLengthBits))); 73 return WebCryptoKeyAlgorithm(id, wrapUnique(new WebCryptoAesKeyAlgorithmPara ms(keyLengthBits)));
73 } 74 }
74 75
75 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createHmac(WebCryptoAlgorithmId has h, unsigned keyLengthBits) 76 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createHmac(WebCryptoAlgorithmId has h, unsigned keyLengthBits)
76 { 77 {
77 if (!WebCryptoAlgorithm::isHash(hash)) 78 if (!WebCryptoAlgorithm::isHash(hash))
78 return WebCryptoKeyAlgorithm(); 79 return WebCryptoKeyAlgorithm();
79 return WebCryptoKeyAlgorithm(WebCryptoAlgorithmIdHmac, adoptPtr(new WebCrypt oHmacKeyAlgorithmParams(createHash(hash), keyLengthBits))); 80 return WebCryptoKeyAlgorithm(WebCryptoAlgorithmIdHmac, wrapUnique(new WebCry ptoHmacKeyAlgorithmParams(createHash(hash), keyLengthBits)));
80 } 81 }
81 82
82 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsaHashed(WebCryptoAlgorithmI d id, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize, WebCryptoAlgorithmId hash) 83 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsaHashed(WebCryptoAlgorithmI d id, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize, WebCryptoAlgorithmId hash)
83 { 84 {
84 // FIXME: Verify that id is an RSA algorithm which expects a hash 85 // FIXME: Verify that id is an RSA algorithm which expects a hash
85 if (!WebCryptoAlgorithm::isHash(hash)) 86 if (!WebCryptoAlgorithm::isHash(hash))
86 return WebCryptoKeyAlgorithm(); 87 return WebCryptoKeyAlgorithm();
87 return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoRsaHashedKeyAlgorithm Params(modulusLengthBits, publicExponent, publicExponentSize, createHash(hash))) ); 88 return WebCryptoKeyAlgorithm(id, wrapUnique(new WebCryptoRsaHashedKeyAlgorit hmParams(modulusLengthBits, publicExponent, publicExponentSize, createHash(hash) )));
88 } 89 }
89 90
90 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createEc(WebCryptoAlgorithmId id, W ebCryptoNamedCurve namedCurve) 91 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createEc(WebCryptoAlgorithmId id, W ebCryptoNamedCurve namedCurve)
91 { 92 {
92 return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoEcKeyAlgorithmParams( namedCurve))); 93 return WebCryptoKeyAlgorithm(id, wrapUnique(new WebCryptoEcKeyAlgorithmParam s(namedCurve)));
93 } 94 }
94 95
95 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createWithoutParams(WebCryptoAlgori thmId id) 96 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createWithoutParams(WebCryptoAlgori thmId id)
96 { 97 {
97 if (!WebCryptoAlgorithm::isKdf(id)) 98 if (!WebCryptoAlgorithm::isKdf(id))
98 return WebCryptoKeyAlgorithm(); 99 return WebCryptoKeyAlgorithm();
99 return WebCryptoKeyAlgorithm(id, nullptr); 100 return WebCryptoKeyAlgorithm(id, nullptr);
100 } 101 }
101 102
102 bool WebCryptoKeyAlgorithm::isNull() const 103 bool WebCryptoKeyAlgorithm::isNull() const
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 { 163 {
163 m_private = other.m_private; 164 m_private = other.m_private;
164 } 165 }
165 166
166 void WebCryptoKeyAlgorithm::reset() 167 void WebCryptoKeyAlgorithm::reset()
167 { 168 {
168 m_private.reset(); 169 m_private.reset();
169 } 170 }
170 171
171 } // namespace blink 172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698