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" | 14 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
15 #include "third_party/WebKit/public/platform/WebCrypto.h" // TODO(eroman): dele
te | |
16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 15 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
17 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 16 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 namespace webcrypto { | 20 namespace webcrypto { |
22 | 21 |
23 class Status; | 22 class Status; |
24 | 23 |
25 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a | 24 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a |
26 // convenience function for getting the pointer, and should not be used beyond | 25 // convenience function for getting the pointer, and should not be used beyond |
27 // the expected lifetime of |data|. | 26 // the expected lifetime of |data|. |
28 CONTENT_EXPORT const uint8* Uint8VectorStart(const std::vector<uint8>& data); | 27 CONTENT_EXPORT const uint8* Uint8VectorStart(const std::vector<uint8>& data); |
29 | 28 |
30 // Shrinks a WebArrayBuffer to a new size. | 29 // Shrinks a WebArrayBuffer to a new size. |
31 // TODO(eroman): This works by re-allocating a new buffer. It would be better if | 30 // TODO(eroman): This works by re-allocating a new buffer. It would be better if |
32 // the WebArrayBuffer could just be truncated instead. | 31 // the WebArrayBuffer could just be truncated instead. |
33 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned int new_size); | 32 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned int new_size); |
34 | 33 |
35 // Creates a WebArrayBuffer from a uint8 byte array | 34 // Creates a WebArrayBuffer from a uint8 byte array |
36 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data, | 35 blink::WebArrayBuffer CreateArrayBuffer(const uint8* data, |
37 unsigned int data_size); | 36 unsigned int data_size); |
38 | 37 |
39 // TODO(eroman): Move this to JWK file. | |
40 // This function decodes unpadded 'base64url' encoded data, as described in | 38 // This function decodes unpadded 'base64url' encoded data, as described in |
41 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. | 39 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. |
42 // In Web Crypto, this type of encoding is only used inside JWK. | 40 // In Web Crypto, this type of encoding is only used inside JWK. |
43 CONTENT_EXPORT bool Base64DecodeUrlSafe(const std::string& input, | 41 CONTENT_EXPORT bool Base64DecodeUrlSafe(const std::string& input, |
44 std::string* output); | 42 std::string* output); |
45 | 43 |
46 // Returns an unpadded 'base64url' encoding of the input data, the opposite of | 44 // Returns an unpadded 'base64url' encoding of the input data, the opposite of |
47 // Base64DecodeUrlSafe() above. | 45 // Base64DecodeUrlSafe() above. |
48 std::string Base64EncodeUrlSafe(const base::StringPiece& input); | 46 std::string Base64EncodeUrlSafe(const base::StringPiece& input); |
49 std::string Base64EncodeUrlSafe(const std::vector<uint8>& input); | 47 std::string Base64EncodeUrlSafe(const std::vector<uint8>& input); |
(...skipping 23 matching lines...) Expand all Loading... |
73 // algorithm that is not SHA*. | 71 // algorithm that is not SHA*. |
74 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( | 72 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( |
75 blink::WebCryptoAlgorithmId hash_id); | 73 blink::WebCryptoAlgorithmId hash_id); |
76 | 74 |
77 // Creates an import algorithm for RSA algorithms that take a hash. | 75 // Creates an import algorithm for RSA algorithms that take a hash. |
78 // It is an error to call this with a hash_id that is not a SHA*. | 76 // It is an error to call this with a hash_id that is not a SHA*. |
79 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( | 77 CONTENT_EXPORT blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( |
80 blink::WebCryptoAlgorithmId id, | 78 blink::WebCryptoAlgorithmId id, |
81 blink::WebCryptoAlgorithmId hash_id); | 79 blink::WebCryptoAlgorithmId hash_id); |
82 | 80 |
83 // TODO(eroman): Move these to jwk.cc | |
84 // Creates an RSASSA-PKCS1-v1_5 algorithm. It is an error to call this with a | |
85 // hash_id that is not a SHA*. | |
86 blink::WebCryptoAlgorithm CreateRsaSsaImportAlgorithm( | |
87 blink::WebCryptoAlgorithmId hash_id); | |
88 | |
89 // Creates an RSA-OAEP algorithm. It is an error to call this with a hash_id | |
90 // that is not a SHA*. | |
91 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( | |
92 blink::WebCryptoAlgorithmId hash_id); | |
93 | |
94 // TODO(eroman): Move to shared_crypto.cc | |
95 // Returns the internal block size for SHA-* | |
96 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id); | |
97 | |
98 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 81 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
99 unsigned int keylen_bytes, | 82 unsigned int keylen_bytes, |
100 blink::WebCryptoKeyAlgorithm* key_algorithm); | 83 blink::WebCryptoKeyAlgorithm* key_algorithm); |
101 | 84 |
102 } // namespace webcrypto | 85 } // namespace webcrypto |
103 | 86 |
104 } // namespace content | 87 } // namespace content |
105 | 88 |
106 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | 89 #endif // CONTENT_CHILD_WEBCRYPTO_WEBCRYPTO_UTIL_H_ |
OLD | NEW |