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

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

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

Powered by Google App Engine
This is Rietveld 408576698