Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | |
| 6 #define CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 #include "base/basictypes.h" | |
| 12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | |
| 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 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 | |
| 19 // the expected lifetime of |data|. | |
| 20 const uint8* Start(const std::vector<uint8>& data); | |
| 21 | |
| 22 // Shrinks a WebArrayBuffer to a new size. | |
| 23 // TODO(eroman): This works by re-allocating a new buffer. It would be better if | |
| 24 // the WebArrayBuffer could just be truncated instead. | |
| 25 void ShrinkBuffer(WebKit::WebArrayBuffer* buffer, unsigned new_size); | |
| 26 | |
| 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 | |
| 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. | |
| 33 bool Base64DecodeUrlSafe(const std::string& input, std::string* output); | |
| 34 | |
| 35 // Returns the "hash" param for an algorithm if it exists, otherwise return | |
|
eroman
2013/11/09 02:22:14
nit: "otherwise return" --> "otherwise returns"
padolph
2013/11/11 00:47:39
Done.
| |
| 36 // a null algorithm. | |
| 37 WebKit::WebCryptoAlgorithm GetInnerHashAlgorithm( | |
| 38 const WebKit::WebCryptoAlgorithm& algorithm); | |
| 39 | |
| 40 // Creates a WebCryptoAlgorithm without any parameters. | |
| 41 WebKit::WebCryptoAlgorithm CreateAlgorithm(WebKit::WebCryptoAlgorithmId id); | |
| 42 | |
| 43 // Creates an HMAC algorithm whose inner hash algorithm is determined by the | |
| 44 // specified hash output length. It is an error to call this method with an | |
| 45 // unsupported hash output length. | |
| 46 WebKit::WebCryptoAlgorithm CreateHmacAlgorithmByHashOutputLen( | |
| 47 unsigned short hash_output_length_bits); | |
| 48 | |
| 49 // Creates an HMAC algorithm whose inner hash algorithm is determined by the | |
| 50 // specified algorithm ID. It is an error to call this method with a hash | |
| 51 // algorithm that is not SHA*. | |
| 52 WebKit::WebCryptoAlgorithm CreateHmacAlgorithmByHashId( | |
| 53 WebKit::WebCryptoAlgorithmId hash_id); | |
| 54 | |
| 55 // Creates an HMAC algorithm whose parameters struct is compatible with key | |
| 56 // generation. It is an error to call this with a hash_id that is not a SHA*. | |
| 57 // The key_length_bytes parameter is optional, with zero meaning unspecified. | |
|
eroman
2013/11/09 02:22:14
Good comments.
| |
| 58 WebKit::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm( | |
| 59 WebKit::WebCryptoAlgorithmId hash_id, | |
| 60 unsigned key_length_bytes); | |
| 61 | |
| 62 // Creates an RSASSA-PKCS1-v1_5 algorithm. It is an error to call this with a | |
| 63 // hash_id that is not a SHA*. | |
| 64 WebKit::WebCryptoAlgorithm CreateRsaSsaAlgorithm( | |
| 65 WebKit::WebCryptoAlgorithmId hash_id); | |
| 66 | |
| 67 // Creates an RSA-OAEP algorithm. It is an error to call this with a hash_id | |
| 68 // that is not a SHA*. | |
| 69 WebKit::WebCryptoAlgorithm CreateRsaOaepAlgorithm( | |
| 70 WebKit::WebCryptoAlgorithmId hash_id); | |
| 71 | |
| 72 // Creates an AES-CBC algorithm. | |
| 73 WebKit::WebCryptoAlgorithm CreateAesCbcAlgorithm(const std::vector<uint8>& iv); | |
| 74 | |
| 75 // Creates and AES-GCM algorithm. | |
| 76 WebKit::WebCryptoAlgorithm CreateAesGcmAlgorithm( | |
| 77 const std::vector<uint8>& iv, | |
| 78 const std::vector<uint8>& additional_data, | |
| 79 uint8 tag_length_bytes); | |
| 80 | |
| 81 // Creates an AES-CBC algorithm whose parameters struct is compatible with key | |
| 82 // generation. | |
| 83 WebKit::WebCryptoAlgorithm CreateAesCbcKeyGenAlgorithm( | |
| 84 unsigned short key_length_bits); | |
| 85 | |
| 86 // Creates an AES-GCM algorithm whose parameters struct is compatible with key | |
| 87 // generation. | |
| 88 WebKit::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm( | |
| 89 unsigned short key_length_bits); | |
| 90 | |
| 91 } // namespace content | |
| 92 | |
| 93 #endif // CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_ | |
| OLD | NEW |