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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 algorithm.id(), keylen_bytes * 8); | 223 algorithm.id(), keylen_bytes * 8); |
218 return true; | 224 return true; |
219 default: | 225 default: |
220 return false; | 226 return false; |
221 } | 227 } |
222 } | 228 } |
223 | 229 |
224 } // namespace webcrypto | 230 } // namespace webcrypto |
225 | 231 |
226 } // namespace content | 232 } // namespace content |
OLD | NEW |