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

Side by Side Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 19401003: Revert "WebCrypto: Add SHA-1 support to crypto.subtle.digest()." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.cpp ('k') | Source/web/WebArrayBuffer.cpp » ('j') | 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Google, Inc. ("Google") nor the names of 13 * 3. Neither the name of Google, Inc. ("Google") nor the names of
14 * its contributors may be used to endorse or promote products derived 14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission. 15 * from this software without specific prior written permission.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY 17 * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29
29 #include "config.h" 30 #include "config.h"
30 #include "modules/crypto/SubtleCrypto.h" 31 #include "modules/crypto/SubtleCrypto.h"
31 32
32 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
33 #include "modules/crypto/CryptoOperation.h" 34 #include "modules/crypto/CryptoOperation.h"
34 #include "modules/crypto/NormalizeAlgorithm.h" 35 #include "modules/crypto/NormalizeAlgorithm.h"
35 #include "public/platform/WebArrayBuffer.h" // FIXME: temporary
36 #include "public/platform/WebCrypto.h"
37 #include "wtf/ArrayBuffer.h" 36 #include "wtf/ArrayBuffer.h"
38 #include "wtf/ArrayBufferView.h" 37 #include "wtf/ArrayBufferView.h"
39 #include "wtf/SHA1.h" // FIXME: temporary
40
41 38
42 namespace WebCore { 39 namespace WebCore {
43 40
44 namespace {
45
46 // FIXME: The following are temporary implementations of what *should* go on the
47 // embedder's side. Since SHA1 is easily implemented, this serves as
48 // a useful proof of concept to get layout tests up and running and
49 // returning correct results, until the embedder's side is implemented.
50 //------------------------------------------------------------------------------
51 class DummyOperation : public WebKit::WebCryptoOperation {
52 public:
53 virtual void process(const unsigned char* bytes, size_t size) OVERRIDE
54 {
55 ASSERT_NOT_REACHED();
56 }
57 virtual void abort() OVERRIDE
58 {
59 delete this;
60 }
61 virtual void finish(WebKit::WebCryptoOperationResult* result) OVERRIDE
62 {
63 ASSERT_NOT_REACHED();
64 }
65 };
66
67 class MockSha1Operation : public DummyOperation {
68 public:
69 virtual void process(const unsigned char* bytes, size_t size) OVERRIDE
70 {
71 m_sha1.addBytes(bytes, size);
72 }
73
74 virtual void finish(WebKit::WebCryptoOperationResult* result) OVERRIDE
75 {
76 Vector<uint8_t, 20> hash;
77 m_sha1.computeHash(hash);
78
79 WebKit::WebArrayBuffer buffer = WebKit::WebArrayBuffer::create(hash.size (), 1);
80 memcpy(buffer.data(), hash.data(), hash.size());
81
82 result->setArrayBuffer(buffer);
83 delete this;
84 }
85
86 private:
87 SHA1 m_sha1;
88 };
89 //------------------------------------------------------------------------------
90
91 } // namespace
92
93 SubtleCrypto::SubtleCrypto() 41 SubtleCrypto::SubtleCrypto()
94 { 42 {
95 ScriptWrappable::init(this); 43 ScriptWrappable::init(this);
96 } 44 }
97 45
98 PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm , ExceptionCode& ec) 46 PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm , ExceptionCode& ec)
99 { 47 {
100 WebKit::WebCryptoAlgorithm algorithm; 48 WebKit::WebCryptoAlgorithm algorithm;
101 if (!normalizeAlgorithm(rawAlgorithm, Encrypt, algorithm, ec)) 49 if (!normalizeAlgorithm(rawAlgorithm, Encrypt, algorithm, ec))
102 return 0; 50 return 0;
103 return CryptoOperation::create(algorithm, new DummyOperation); 51 return CryptoOperation::create(algorithm);
104 } 52 }
105 53
106 PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm , ExceptionCode& ec) 54 PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm , ExceptionCode& ec)
107 { 55 {
108 WebKit::WebCryptoAlgorithm algorithm; 56 WebKit::WebCryptoAlgorithm algorithm;
109 if (!normalizeAlgorithm(rawAlgorithm, Decrypt, algorithm, ec)) 57 if (!normalizeAlgorithm(rawAlgorithm, Decrypt, algorithm, ec))
110 return 0; 58 return 0;
111 return CryptoOperation::create(algorithm, new DummyOperation); 59 return CryptoOperation::create(algorithm);
112 } 60 }
113 61
114 PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, E xceptionCode& ec) 62 PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, E xceptionCode& ec)
115 { 63 {
116 WebKit::WebCryptoAlgorithm algorithm; 64 WebKit::WebCryptoAlgorithm algorithm;
117 if (!normalizeAlgorithm(rawAlgorithm, Sign, algorithm, ec)) 65 if (!normalizeAlgorithm(rawAlgorithm, Sign, algorithm, ec))
118 return 0; 66 return 0;
119 return CryptoOperation::create(algorithm, new DummyOperation); 67 return CryptoOperation::create(algorithm);
120 } 68 }
121 69
122 PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawA lgorithm, ExceptionCode& ec) 70 PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawA lgorithm, ExceptionCode& ec)
123 { 71 {
124 WebKit::WebCryptoAlgorithm algorithm; 72 WebKit::WebCryptoAlgorithm algorithm;
125 if (!normalizeAlgorithm(rawAlgorithm, Verify, algorithm, ec)) 73 if (!normalizeAlgorithm(rawAlgorithm, Verify, algorithm, ec))
126 return 0; 74 return 0;
127 return CryptoOperation::create(algorithm, new DummyOperation); 75 return CryptoOperation::create(algorithm);
128 } 76 }
129 77
130 PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionCode& ec) 78 PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionCode& ec)
131 { 79 {
132 WebKit::WebCryptoAlgorithm algorithm; 80 WebKit::WebCryptoAlgorithm algorithm;
133 if (!normalizeAlgorithm(rawAlgorithm, Digest, algorithm, ec)) 81 if (!normalizeAlgorithm(rawAlgorithm, Digest, algorithm, ec))
134 return 0; 82 return 0;
135 83 return CryptoOperation::create(algorithm);
136 // FIXME: Create the WebCryptoImplementation by calling out to
137 // Platform::crypto() instead.
138 WebKit::WebCryptoOperation* operationImpl = algorithm.id() == WebKit::WebCry ptoAlgorithmIdSha1 ? new MockSha1Operation : new DummyOperation;
139
140 return CryptoOperation::create(algorithm, operationImpl);
141 } 84 }
142 85
143 } // namespace WebCore 86 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.cpp ('k') | Source/web/WebArrayBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698