| OLD | NEW |
| 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 "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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { | 214 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { |
| 215 std::string base64EncodedText(input); | 215 std::string base64EncodedText(input); |
| 216 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); | 216 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); |
| 217 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); | 217 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); |
| 218 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); | 218 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); |
| 219 return base::Base64Decode(base64EncodedText, output); | 219 return base::Base64Decode(base64EncodedText, output); |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id) { | 222 bool IsHashAlgorithm(blink::WebCryptoAlgorithmId alg_id) { |
| 223 return alg_id == blink::WebCryptoAlgorithmIdSha1 || | 223 return alg_id == blink::WebCryptoAlgorithmIdSha1 || |
| 224 alg_id == blink::WebCryptoAlgorithmIdSha224 || | |
| 225 alg_id == blink::WebCryptoAlgorithmIdSha256 || | 224 alg_id == blink::WebCryptoAlgorithmIdSha256 || |
| 226 alg_id == blink::WebCryptoAlgorithmIdSha384 || | 225 alg_id == blink::WebCryptoAlgorithmIdSha384 || |
| 227 alg_id == blink::WebCryptoAlgorithmIdSha512; | 226 alg_id == blink::WebCryptoAlgorithmIdSha512; |
| 228 } | 227 } |
| 229 | 228 |
| 230 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( | 229 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( |
| 231 const blink::WebCryptoAlgorithm& algorithm) { | 230 const blink::WebCryptoAlgorithm& algorithm) { |
| 232 DCHECK(!algorithm.isNull()); | 231 DCHECK(!algorithm.isNull()); |
| 233 switch (algorithm.paramsType()) { | 232 switch (algorithm.paramsType()) { |
| 234 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: | 233 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 blink::WebCryptoAlgorithmId hash_id) { | 267 blink::WebCryptoAlgorithmId hash_id) { |
| 269 DCHECK(IsHashAlgorithm(hash_id)); | 268 DCHECK(IsHashAlgorithm(hash_id)); |
| 270 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 269 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 271 blink::WebCryptoAlgorithmIdRsaOaep, | 270 blink::WebCryptoAlgorithmIdRsaOaep, |
| 272 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | 271 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); |
| 273 } | 272 } |
| 274 | 273 |
| 275 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { | 274 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { |
| 276 switch (hash_id) { | 275 switch (hash_id) { |
| 277 case blink::WebCryptoAlgorithmIdSha1: | 276 case blink::WebCryptoAlgorithmIdSha1: |
| 278 case blink::WebCryptoAlgorithmIdSha224: | |
| 279 case blink::WebCryptoAlgorithmIdSha256: | 277 case blink::WebCryptoAlgorithmIdSha256: |
| 280 return 64; | 278 return 64; |
| 281 case blink::WebCryptoAlgorithmIdSha384: | 279 case blink::WebCryptoAlgorithmIdSha384: |
| 282 case blink::WebCryptoAlgorithmIdSha512: | 280 case blink::WebCryptoAlgorithmIdSha512: |
| 283 return 128; | 281 return 128; |
| 284 default: | 282 default: |
| 285 NOTREACHED(); | 283 NOTREACHED(); |
| 286 return 0; | 284 return 0; |
| 287 } | 285 } |
| 288 } | 286 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 308 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 306 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
| 309 return true; | 307 return true; |
| 310 default: | 308 default: |
| 311 return false; | 309 return false; |
| 312 } | 310 } |
| 313 } | 311 } |
| 314 | 312 |
| 315 } // namespace webcrypto | 313 } // namespace webcrypto |
| 316 | 314 |
| 317 } // namespace content | 315 } // namespace content |
| OLD | NEW |