| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_util.h" | 5 #include "content/renderer/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 "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 if (new_size == buffer->byteLength()) | 44 if (new_size == buffer->byteLength()) |
| 45 return; | 45 return; |
| 46 | 46 |
| 47 blink::WebArrayBuffer new_buffer = blink::WebArrayBuffer::create(new_size, 1); | 47 blink::WebArrayBuffer new_buffer = blink::WebArrayBuffer::create(new_size, 1); |
| 48 DCHECK(!new_buffer.isNull()); | 48 DCHECK(!new_buffer.isNull()); |
| 49 memcpy(new_buffer.data(), buffer->data(), new_size); | 49 memcpy(new_buffer.data(), buffer->data(), new_size); |
| 50 *buffer = new_buffer; | 50 *buffer = new_buffer; |
| 51 } | 51 } |
| 52 | 52 |
| 53 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data, unsigned data_size) { |
| 54 blink::WebArrayBuffer buffer = blink::WebArrayBuffer::create(data_size, 1); |
| 55 DCHECK(!buffer.isNull()); |
| 56 memcpy(buffer.data(), data, data_size); |
| 57 return buffer; |
| 58 } |
| 59 |
| 53 // This function decodes unpadded 'base64url' encoded data, as described in | 60 // This function decodes unpadded 'base64url' encoded data, as described in |
| 54 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. To do this, first | 61 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. To do this, first |
| 55 // change the incoming data to 'base64' encoding by applying the appropriate | 62 // change the incoming data to 'base64' encoding by applying the appropriate |
| 56 // transformation including adding padding if required, and then call a base64 | 63 // transformation including adding padding if required, and then call a base64 |
| 57 // decoder. | 64 // decoder. |
| 58 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { | 65 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { |
| 59 std::string base64EncodedText(input); | 66 std::string base64EncodedText(input); |
| 60 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); | 67 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); |
| 61 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); | 68 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); |
| 62 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); | 69 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 195 |
| 189 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( | 196 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( |
| 190 unsigned short key_length_bits) { | 197 unsigned short key_length_bits) { |
| 191 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, | 198 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, |
| 192 key_length_bits); | 199 key_length_bits); |
| 193 } | 200 } |
| 194 | 201 |
| 195 } // namespace webcrypto | 202 } // namespace webcrypto |
| 196 | 203 |
| 197 } // namespace content | 204 } // namespace content |
| OLD | NEW |