[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 5 | #ifndef COMPONENTS_WEBCRYPTO_CRYPTO_DATA_H_ |
| 6 | #define COMPONENTS_WEBCRYPTO_CRYPTO_DATA_H_ |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 11 | #include "third_party/WebKit/public/platform/WebVector.h" |
| 12 | |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 13 | namespace webcrypto { |
| 14 | |
| 15 | // Helper to pass around a range of immutable bytes. This is conceptually |
| 16 | // similar to base::StringPiece, but for crypto byte data. |
| 17 | // |
| 18 | // The data used at construction is NOT owned, and should remain valid as long |
| 19 | // as the CryptoData is being used. |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 20 | class CryptoData { |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 21 | public: |
| 22 | // Constructs empty data. |
| 23 | CryptoData(); |
| 24 | |
| 25 | CryptoData(const unsigned char* bytes, unsigned int byte_length); |
| 26 | |
| 27 | // These constructors do NOT copy the data. Hence the base pointer should |
| 28 | // remain valid for the lifetime of CryptoData. |
| 29 | explicit CryptoData(const std::vector<unsigned char>& bytes); |
| 30 | explicit CryptoData(const std::string& bytes); |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 31 | explicit CryptoData(const blink::WebVector<unsigned char>& bytes); |
| 32 | |
| 33 | const unsigned char* bytes() const { return bytes_; } |
| 34 | unsigned int byte_length() const { return byte_length_; } |
| 35 | |
| 36 | private: |
| 37 | const unsigned char* const bytes_; |
| 38 | const unsigned int byte_length_; |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // namespace webcrypto |
| 42 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 43 | #endif // COMPONENTS_WEBCRYPTO_CRYPTO_DATA_H_ |