| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { | 66 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { |
| 67 std::string base64EncodedText(input); | 67 std::string base64EncodedText(input); |
| 68 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); | 68 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); |
| 69 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); | 69 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); |
| 70 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); | 70 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); |
| 71 return base::Base64Decode(base64EncodedText, output); | 71 return base::Base64Decode(base64EncodedText, output); |
| 72 } | 72 } |
| 73 | 73 |
| 74 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( | 74 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( |
| 75 const blink::WebCryptoAlgorithm& algorithm) { | 75 const blink::WebCryptoAlgorithm& algorithm) { |
| 76 if (algorithm.hmacParams()) | 76 DCHECK(!algorithm.isNull()); |
| 77 return algorithm.hmacParams()->hash(); | 77 switch (algorithm.id()) { |
| 78 if (algorithm.hmacKeyParams()) | 78 case blink::WebCryptoAlgorithmIdHmac: |
| 79 return algorithm.hmacKeyParams()->hash(); | 79 if (algorithm.hmacParams()) |
| 80 if (algorithm.rsaSsaParams()) | 80 return algorithm.hmacParams()->hash(); |
| 81 return algorithm.rsaSsaParams()->hash(); | 81 else if (algorithm.hmacKeyParams()) |
| 82 if (algorithm.rsaOaepParams()) | 82 return algorithm.hmacKeyParams()->hash(); |
| 83 return algorithm.rsaOaepParams()->hash(); | 83 break; |
| 84 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 85 if (algorithm.rsaOaepParams()) |
| 86 return algorithm.rsaOaepParams()->hash(); |
| 87 break; |
| 88 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 89 if (algorithm.rsaSsaParams()) |
| 90 return algorithm.rsaSsaParams()->hash(); |
| 91 break; |
| 92 default: |
| 93 break; |
| 94 } |
| 84 return blink::WebCryptoAlgorithm::createNull(); | 95 return blink::WebCryptoAlgorithm::createNull(); |
| 85 } | 96 } |
| 86 | 97 |
| 87 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) { | 98 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) { |
| 88 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL); | 99 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL); |
| 89 } | 100 } |
| 90 | 101 |
| 91 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashOutputLen( | 102 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashOutputLen( |
| 92 unsigned short hash_output_length_bits) { | 103 unsigned short hash_output_length_bits) { |
| 93 blink::WebCryptoAlgorithmId hash_id; | 104 blink::WebCryptoAlgorithmId hash_id; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 207 |
| 197 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( | 208 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( |
| 198 unsigned short key_length_bits) { | 209 unsigned short key_length_bits) { |
| 199 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, | 210 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, |
| 200 key_length_bits); | 211 key_length_bits); |
| 201 } | 212 } |
| 202 | 213 |
| 203 } // namespace webcrypto | 214 } // namespace webcrypto |
| 204 | 215 |
| 205 } // namespace content | 216 } // namespace content |
| OLD | NEW |