| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 explicit Input(const base::StringPiece& sp); | 56 explicit Input(const base::StringPiece& sp); |
| 57 | 57 |
| 58 // Creates an Input from a std::string. The lifetimes are a bit subtle when | 58 // Creates an Input from a std::string. The lifetimes are a bit subtle when |
| 59 // using this function: The constructed Input is only valid so long as |s| is | 59 // using this function: The constructed Input is only valid so long as |s| is |
| 60 // still alive and not mutated. | 60 // still alive and not mutated. |
| 61 Input(const std::string* s); | 61 Input(const std::string* s); |
| 62 | 62 |
| 63 // Returns the length in bytes of an Input's data. | 63 // Returns the length in bytes of an Input's data. |
| 64 size_t Length() const { return len_; } | 64 size_t Length() const { return len_; } |
| 65 | 65 |
| 66 // Return true if the Input's data and |other|'s data are byte-wise equal. | |
| 67 bool Equals(const Input& other) const; | |
| 68 | |
| 69 // Returns a pointer to the Input's data. This method is marked as "unsafe" | 66 // Returns a pointer to the Input's data. This method is marked as "unsafe" |
| 70 // because access to the Input's data should be done through ByteReader | 67 // because access to the Input's data should be done through ByteReader |
| 71 // instead. This method should only be used where using a ByteReader truly | 68 // instead. This method should only be used where using a ByteReader truly |
| 72 // is not an option. | 69 // is not an option. |
| 73 const uint8_t* UnsafeData() const { return data_; } | 70 const uint8_t* UnsafeData() const { return data_; } |
| 74 | 71 |
| 75 // Returns a copy of the data represented by this object as a std::string. | 72 // Returns a copy of the data represented by this object as a std::string. |
| 76 std::string AsString() const; | 73 std::string AsString() const; |
| 77 | 74 |
| 78 // Returns a StringPiece pointing to the same data as the Input. The resulting | 75 // Returns a StringPiece pointing to the same data as the Input. The resulting |
| 79 // StringPiece must not outlive the data that was used to construct this | 76 // StringPiece must not outlive the data that was used to construct this |
| 80 // Input. | 77 // Input. |
| 81 base::StringPiece AsStringPiece() const; | 78 base::StringPiece AsStringPiece() const; |
| 82 | 79 |
| 83 private: | 80 private: |
| 84 // This constructor is deleted to prevent constructing an Input from a | 81 // This constructor is deleted to prevent constructing an Input from a |
| 85 // std::string r-value. Since the Input points to memory owned by another | 82 // std::string r-value. Since the Input points to memory owned by another |
| 86 // object, such an Input would point to invalid memory. Without this deleted | 83 // object, such an Input would point to invalid memory. Without this deleted |
| 87 // constructor, a std::string could be passed in to the base::StringPiece | 84 // constructor, a std::string could be passed in to the base::StringPiece |
| 88 // constructor because of StringPiece's implicit constructor. | 85 // constructor because of StringPiece's implicit constructor. |
| 89 Input(std::string) = delete; | 86 Input(std::string) = delete; |
| 90 const uint8_t* data_; | 87 const uint8_t* data_; |
| 91 size_t len_; | 88 size_t len_; |
| 92 }; | 89 }; |
| 93 | 90 |
| 91 // Return true if |lhs|'s data and |rhs|'s data are byte-wise equal. |
| 92 NET_EXPORT_PRIVATE bool operator==(const Input& lhs, const Input& rhs); |
| 93 |
| 94 // Return true if |lhs|'s data and |rhs|'s data are not byte-wise equal. |
| 95 NET_EXPORT_PRIVATE bool operator!=(const Input& lhs, const Input& rhs); |
| 96 |
| 94 // Returns true if |lhs|'s data is lexicographically less than |rhs|'s data. | 97 // Returns true if |lhs|'s data is lexicographically less than |rhs|'s data. |
| 95 NET_EXPORT_PRIVATE bool operator<(const Input& lhs, const Input& rhs); | 98 NET_EXPORT_PRIVATE bool operator<(const Input& lhs, const Input& rhs); |
| 96 | 99 |
| 97 // This class provides ways to read data from an Input in a bounds-checked way. | 100 // This class provides ways to read data from an Input in a bounds-checked way. |
| 98 // The ByteReader is designed to read through the input sequentially. Once a | 101 // The ByteReader is designed to read through the input sequentially. Once a |
| 99 // byte has been read with a ByteReader, the caller can't go back and re-read | 102 // byte has been read with a ByteReader, the caller can't go back and re-read |
| 100 // that byte with the same reader. Of course, the caller can create multiple | 103 // that byte with the same reader. Of course, the caller can create multiple |
| 101 // ByteReaders for the same input (or copy an existing ByteReader). | 104 // ByteReaders for the same input (or copy an existing ByteReader). |
| 102 // | 105 // |
| 103 // For something simple like a single byte lookahead, the easiest way to do | 106 // For something simple like a single byte lookahead, the easiest way to do |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 explicit Mark(const uint8_t* ptr); | 179 explicit Mark(const uint8_t* ptr); |
| 177 Mark(); | 180 Mark(); |
| 178 const uint8_t* ptr_; | 181 const uint8_t* ptr_; |
| 179 }; | 182 }; |
| 180 | 183 |
| 181 } // namespace der | 184 } // namespace der |
| 182 | 185 |
| 183 } // namespace net | 186 } // namespace net |
| 184 | 187 |
| 185 #endif // NET_DER_INPUT_H_ | 188 #endif // NET_DER_INPUT_H_ |
| OLD | NEW |