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

Side by Side Diff: content/child/webcrypto/webcrypto_util.cc

Issue 233733004: [webcrypto] Make operations run on worker threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix argument ordering bug Created 6 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/webcrypto/webcrypto_util.h" 5 #include "content/child/webcrypto/webcrypto_util.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/child/webcrypto/status.h" 10 #include "content/child/webcrypto/status.h"
11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
13 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 13 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 namespace webcrypto { 17 namespace webcrypto {
18 18
19 const uint8* Uint8VectorStart(const std::vector<uint8>& data) { 19 const uint8* Uint8VectorStart(const std::vector<uint8>& data) {
20 if (data.empty()) 20 if (data.empty())
21 return NULL; 21 return NULL;
22 return &data[0]; 22 return &data[0];
23 } 23 }
24 24
25 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned int new_size) { 25 uint8* Uint8VectorStart(std::vector<uint8>* data) {
26 DCHECK_LE(new_size, buffer->byteLength()); 26 if (data->empty())
27 27 return NULL;
28 if (new_size == buffer->byteLength()) 28 return &(*data)[0];
29 return;
30
31 blink::WebArrayBuffer new_buffer = blink::WebArrayBuffer::create(new_size, 1);
32 DCHECK(!new_buffer.isNull());
33 memcpy(new_buffer.data(), buffer->data(), new_size);
34 *buffer = new_buffer;
35 }
36
37 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data,
38 unsigned int data_size) {
39 blink::WebArrayBuffer buffer = blink::WebArrayBuffer::create(data_size, 1);
40 DCHECK(!buffer.isNull());
41 if (data_size) // data_size == 0 might mean the data pointer is invalid
42 memcpy(buffer.data(), data, data_size);
43 return buffer;
44 } 29 }
45 30
46 // This function decodes unpadded 'base64url' encoded data, as described in 31 // This function decodes unpadded 'base64url' encoded data, as described in
47 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. To do this, first 32 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. To do this, first
48 // change the incoming data to 'base64' encoding by applying the appropriate 33 // change the incoming data to 'base64' encoding by applying the appropriate
49 // transformation including adding padding if required, and then call a base64 34 // transformation including adding padding if required, and then call a base64
50 // decoder. 35 // decoder.
51 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { 36 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) {
52 std::string base64EncodedText(input); 37 std::string base64EncodedText(input);
53 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); 38 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+');
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 algorithm.id(), keylen_bytes * 8); 182 algorithm.id(), keylen_bytes * 8);
198 return true; 183 return true;
199 default: 184 default:
200 return false; 185 return false;
201 } 186 }
202 } 187 }
203 188
204 } // namespace webcrypto 189 } // namespace webcrypto
205 190
206 } // namespace content 191 } // namespace content
OLDNEW
« content/child/webcrypto/webcrypto_impl.cc ('K') | « content/child/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698