OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 NET_DER_INPUT_H_ | 5 #ifndef NET_DER_INPUT_H_ |
6 #define NET_DER_INPUT_H_ | 6 #define NET_DER_INPUT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... | |
39 class NET_EXPORT_PRIVATE Input { | 39 class NET_EXPORT_PRIVATE Input { |
40 public: | 40 public: |
41 // Creates an empty Input, one from which no data can be read. | 41 // Creates an empty Input, one from which no data can be read. |
42 Input(); | 42 Input(); |
43 | 43 |
44 // Creates an Input from a constant array |data|. | 44 // Creates an Input from a constant array |data|. |
45 template <size_t N> | 45 template <size_t N> |
46 explicit Input(const uint8_t(&data)[N]) | 46 explicit Input(const uint8_t(&data)[N]) |
47 : data_(data), len_(N) {} | 47 : data_(data), len_(N) {} |
48 | 48 |
49 // Creates an Input from a null-terminated constant char array |data|. This is | |
50 // provided as a factory method instead of a constructor to avoid confusion | |
51 // with the similar constructor above which takes an array of uint8_t which is | |
52 // not null terminated. | |
53 template <size_t N> | |
54 static Input FromCString(const char(&data)[N]) { | |
55 return Input(reinterpret_cast<const uint8_t*>(data), N - 1); | |
56 } | |
Ryan Sleevi
2015/05/26 18:53:30
Strictly on a STYLE basis, this shouldn't be inter
| |
57 | |
49 // Creates an Input from the given |data| and |len|. | 58 // Creates an Input from the given |data| and |len|. |
50 Input(const uint8_t* data, size_t len); | 59 Input(const uint8_t* data, size_t len); |
51 | 60 |
52 // Creates an Input from the given string |s|. | |
53 explicit Input(const std::string& s); | |
54 | |
55 // Returns the length in bytes of an Input's data. | 61 // Returns the length in bytes of an Input's data. |
56 size_t Length() const { return len_; } | 62 size_t Length() const { return len_; } |
57 | 63 |
58 // Return true if the Input's data and |other|'s data are byte-wise equal. | 64 // Return true if the Input's data and |other|'s data are byte-wise equal. |
59 bool Equals(const Input& other) const; | 65 bool Equals(const Input& other) const; |
60 | 66 |
61 // Returns a pointer to the Input's data. This method is marked as "unsafe" | 67 // Returns a pointer to the Input's data. This method is marked as "unsafe" |
62 // because access to the Input's data should be done through ByteReader | 68 // because access to the Input's data should be done through ByteReader |
63 // instead. This method should only be used where using a ByteReader truly | 69 // instead. This method should only be used where using a ByteReader truly |
64 // is not an option. | 70 // is not an option. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 explicit Mark(const uint8_t* ptr); | 157 explicit Mark(const uint8_t* ptr); |
152 Mark(); | 158 Mark(); |
153 const uint8_t* ptr_; | 159 const uint8_t* ptr_; |
154 }; | 160 }; |
155 | 161 |
156 } // namespace der | 162 } // namespace der |
157 | 163 |
158 } // namespace net | 164 } // namespace net |
159 | 165 |
160 #endif // NET_DER_INPUT_H_ | 166 #endif // NET_DER_INPUT_H_ |
OLD | NEW |