blob: b66a16a2676743a867a50f0149d78d7d474c699f [file] [log] [blame]
[email protected]04166f82014-02-19 06:11:041// 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
erg56f12322015-04-17 00:51:485#ifndef COMPONENTS_WEBCRYPTO_CRYPTO_DATA_H_
6#define COMPONENTS_WEBCRYPTO_CRYPTO_DATA_H_
[email protected]04166f82014-02-19 06:11:047
8#include <string>
9#include <vector>
10
[email protected]04166f82014-02-19 06:11:0411#include "third_party/WebKit/public/platform/WebVector.h"
12
[email protected]04166f82014-02-19 06:11:0413namespace 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.
erg56f12322015-04-17 00:51:4820class CryptoData {
[email protected]04166f82014-02-19 06:11:0421 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]04166f82014-02-19 06:11:0431 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]04166f82014-02-19 06:11:0439};
40
41} // namespace webcrypto
42
erg56f12322015-04-17 00:51:4843#endif // COMPONENTS_WEBCRYPTO_CRYPTO_DATA_H_