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 "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/child/webcrypto/status.h" | 10 #include "content/child/webcrypto/status.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // inverse of the process above. | 60 // inverse of the process above. |
61 std::string Base64EncodeUrlSafe(const base::StringPiece& input) { | 61 std::string Base64EncodeUrlSafe(const base::StringPiece& input) { |
62 std::string output; | 62 std::string output; |
63 base::Base64Encode(input, &output); | 63 base::Base64Encode(input, &output); |
64 std::replace(output.begin(), output.end(), '+', '-'); | 64 std::replace(output.begin(), output.end(), '+', '-'); |
65 std::replace(output.begin(), output.end(), '/', '_'); | 65 std::replace(output.begin(), output.end(), '/', '_'); |
66 output.erase(std::remove(output.begin(), output.end(), '='), output.end()); | 66 output.erase(std::remove(output.begin(), output.end(), '='), output.end()); |
67 return output; | 67 return output; |
68 } | 68 } |
69 | 69 |
| 70 std::string Base64EncodeUrlSafe(const std::vector<uint8>& input) { |
| 71 const base::StringPiece string_piece( |
| 72 reinterpret_cast<const char*>(Uint8VectorStart(input)), input.size()); |
| 73 return Base64EncodeUrlSafe(string_piece); |
| 74 } |
| 75 |
70 struct JwkToWebCryptoUsage { | 76 struct JwkToWebCryptoUsage { |
71 const char* const jwk_key_op; | 77 const char* const jwk_key_op; |
72 const blink::WebCryptoKeyUsage webcrypto_usage; | 78 const blink::WebCryptoKeyUsage webcrypto_usage; |
73 }; | 79 }; |
74 | 80 |
75 const JwkToWebCryptoUsage kJwkWebCryptoUsageMap[] = { | 81 const JwkToWebCryptoUsage kJwkWebCryptoUsageMap[] = { |
76 {"encrypt", blink::WebCryptoKeyUsageEncrypt}, | 82 {"encrypt", blink::WebCryptoKeyUsageEncrypt}, |
77 {"decrypt", blink::WebCryptoKeyUsageDecrypt}, | 83 {"decrypt", blink::WebCryptoKeyUsageDecrypt}, |
78 {"deriveKey", blink::WebCryptoKeyUsageDeriveKey}, | 84 {"deriveKey", blink::WebCryptoKeyUsageDeriveKey}, |
79 // TODO(padolph): Add 'deriveBits' once supported by Blink. | 85 // TODO(padolph): Add 'deriveBits' once supported by Blink. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 225 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
220 return true; | 226 return true; |
221 default: | 227 default: |
222 return false; | 228 return false; |
223 } | 229 } |
224 } | 230 } |
225 | 231 |
226 } // namespace webcrypto | 232 } // namespace webcrypto |
227 | 233 |
228 } // namespace content | 234 } // namespace content |
OLD | NEW |