OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 5 #ifndef CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
6 #define CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 6 #define CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a | 17 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a |
18 // convenience function for getting the pointer, and should not be used beyond | 18 // convenience function for getting the pointer, and should not be used beyond |
19 // the expected lifetime of |data|. | 19 // the expected lifetime of |data|. |
20 const uint8* Start(const std::vector<uint8>& data); | 20 const uint8* Start(const std::vector<uint8>& data); |
21 | 21 |
22 // Shrinks a WebArrayBuffer to a new size. | 22 // Shrinks a WebArrayBuffer to a new size. |
23 // TODO(eroman): This works by re-allocating a new buffer. It would be better if | 23 // TODO(eroman): This works by re-allocating a new buffer. It would be better if |
24 // the WebArrayBuffer could just be truncated instead. | 24 // the WebArrayBuffer could just be truncated instead. |
25 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size); | 25 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size); |
26 | 26 |
27 // This function decodes unpadded 'base64url' encoded data, as described in | 27 // This function decodes unpadded 'base64url' encoded data, as described in |
28 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. To do this, first | 28 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. |
29 // change the incoming data to 'base64' encoding by applying the appropriate | |
30 // transformation including adding padding if required, and then call a base64 | |
31 // decoder. | |
32 // In Web Crypto, this type of encoding is only used inside JWK. | 29 // In Web Crypto, this type of encoding is only used inside JWK. |
33 bool Base64DecodeUrlSafe(const std::string& input, std::string* output); | 30 bool Base64DecodeUrlSafe(const std::string& input, std::string* output); |
34 | 31 |
35 // Returns the "hash" param for an algorithm if it exists, otherwise returns | 32 // Returns the "hash" param for an algorithm if it exists, otherwise returns |
36 // a null algorithm. | 33 // a null algorithm. |
37 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( | 34 blink::WebCryptoAlgorithm GetInnerHashAlgorithm( |
38 const blink::WebCryptoAlgorithm& algorithm); | 35 const blink::WebCryptoAlgorithm& algorithm); |
39 | 36 |
40 // Creates a WebCryptoAlgorithm without any parameters. | 37 // Creates a WebCryptoAlgorithm without any parameters. |
41 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id); | 38 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 unsigned short key_length_bits); | 81 unsigned short key_length_bits); |
85 | 82 |
86 // Creates an AES-GCM algorithm whose parameters struct is compatible with key | 83 // Creates an AES-GCM algorithm whose parameters struct is compatible with key |
87 // generation. | 84 // generation. |
88 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( | 85 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( |
89 unsigned short key_length_bits); | 86 unsigned short key_length_bits); |
90 | 87 |
91 } // namespace content | 88 } // namespace content |
92 | 89 |
93 #endif // CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 90 #endif // CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
OLD | NEW |