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 #ifndef CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 5 #ifndef CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
6 #define CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 6 #define CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | |
15 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
16 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 15 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 namespace webcrypto { | 19 namespace webcrypto { |
21 | 20 |
22 class Status; | 21 class Status; |
23 | 22 |
24 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a | 23 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a |
25 // convenience function for getting the pointer, and should not be used beyond | 24 // convenience function for getting the pointer, and should not be used beyond |
26 // the expected lifetime of |data|. | 25 // the expected lifetime of |data|. |
27 CONTENT_EXPORT const uint8* Uint8VectorStart(const std::vector<uint8>& data); | 26 CONTENT_EXPORT const uint8* Uint8VectorStart(const std::vector<uint8>& data); |
28 | 27 CONTENT_EXPORT uint8* Uint8VectorStart(std::vector<uint8>* data); |
29 // Shrinks a WebArrayBuffer to a new size. | |
30 // TODO(eroman): This works by re-allocating a new buffer. It would be better if | |
31 // the WebArrayBuffer could just be truncated instead. | |
32 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned int new_size); | |
33 | |
34 // Creates a WebArrayBuffer from a uint8 byte array | |
35 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data, | |
36 unsigned int data_size); | |
37 | 28 |
38 // This function decodes unpadded 'base64url' encoded data, as described in | 29 // This function decodes unpadded 'base64url' encoded data, as described in |
39 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. | 30 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. |
40 // In Web Crypto, this type of encoding is only used inside JWK. | 31 // In Web Crypto, this type of encoding is only used inside JWK. |
41 CONTENT_EXPORT bool Base64DecodeUrlSafe(const std::string& input, | 32 CONTENT_EXPORT bool Base64DecodeUrlSafe(const std::string& input, |
42 std::string* output); | 33 std::string* output); |
43 | 34 |
44 // Returns an unpadded 'base64url' encoding of the input data, the opposite of | 35 // Returns an unpadded 'base64url' encoding of the input data, the opposite of |
45 // Base64DecodeUrlSafe() above. | 36 // Base64DecodeUrlSafe() above. |
46 std::string Base64EncodeUrlSafe(const base::StringPiece& input); | 37 std::string Base64EncodeUrlSafe(const base::StringPiece& input); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 71 |
81 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 72 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
82 unsigned int keylen_bytes, | 73 unsigned int keylen_bytes, |
83 blink::WebCryptoKeyAlgorithm* key_algorithm); | 74 blink::WebCryptoKeyAlgorithm* key_algorithm); |
84 | 75 |
85 } // namespace webcrypto | 76 } // namespace webcrypto |
86 | 77 |
87 } // namespace content | 78 } // namespace content |
88 | 79 |
89 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 80 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
OLD | NEW |