| 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 #include <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/der/input.h" | 10 #include "net/der/input.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace der { | 14 namespace der { |
| 15 | 15 |
| 16 Input::Input() : data_(nullptr), len_(0) { | 16 Input::Input() : data_(nullptr), len_(0) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 Input::Input(const uint8_t* data, size_t len) : data_(data), len_(len) { | 19 Input::Input(const uint8_t* data, size_t len) : data_(data), len_(len) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 Input::Input(const base::StringPiece& in) | 22 Input::Input(const base::StringPiece& in) |
| 23 : data_(reinterpret_cast<const uint8_t*>(in.data())), len_(in.length()) {} | 23 : data_(reinterpret_cast<const uint8_t*>(in.data())), len_(in.length()) {} |
| 24 | 24 |
| 25 Input::Input(const std::string* s) : Input(base::StringPiece(*s)) {} | 25 Input::Input(const std::string* s) : Input(base::StringPiece(*s)) {} |
| 26 | 26 |
| 27 bool Input::Equals(const Input& other) const { | |
| 28 if (len_ != other.len_) | |
| 29 return false; | |
| 30 return memcmp(data_, other.data_, len_) == 0; | |
| 31 } | |
| 32 | |
| 33 std::string Input::AsString() const { | 27 std::string Input::AsString() const { |
| 34 return std::string(reinterpret_cast<const char*>(data_), len_); | 28 return std::string(reinterpret_cast<const char*>(data_), len_); |
| 35 } | 29 } |
| 36 | 30 |
| 37 base::StringPiece Input::AsStringPiece() const { | 31 base::StringPiece Input::AsStringPiece() const { |
| 38 return base::StringPiece(reinterpret_cast<const char*>(data_), len_); | 32 return base::StringPiece(reinterpret_cast<const char*>(data_), len_); |
| 39 } | 33 } |
| 40 | 34 |
| 35 bool operator==(const Input& lhs, const Input& rhs) { |
| 36 if (lhs.Length() != rhs.Length()) |
| 37 return false; |
| 38 return memcmp(lhs.UnsafeData(), rhs.UnsafeData(), lhs.Length()) == 0; |
| 39 } |
| 40 |
| 41 bool operator!=(const Input& lhs, const Input& rhs) { |
| 42 return !(lhs == rhs); |
| 43 } |
| 44 |
| 41 bool operator<(const Input& lhs, const Input& rhs) { | 45 bool operator<(const Input& lhs, const Input& rhs) { |
| 42 return std::lexicographical_compare( | 46 return std::lexicographical_compare( |
| 43 lhs.UnsafeData(), lhs.UnsafeData() + lhs.Length(), rhs.UnsafeData(), | 47 lhs.UnsafeData(), lhs.UnsafeData() + lhs.Length(), rhs.UnsafeData(), |
| 44 rhs.UnsafeData() + rhs.Length()); | 48 rhs.UnsafeData() + rhs.Length()); |
| 45 } | 49 } |
| 46 | 50 |
| 47 ByteReader::ByteReader(const Input& in) | 51 ByteReader::ByteReader(const Input& in) |
| 48 : data_(in.UnsafeData()), len_(in.Length()) { | 52 : data_(in.UnsafeData()), len_(in.Length()) { |
| 49 } | 53 } |
| 50 | 54 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 112 |
| 109 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) { | 113 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) { |
| 110 } | 114 } |
| 111 | 115 |
| 112 Mark::Mark() : ptr_(nullptr) { | 116 Mark::Mark() : ptr_(nullptr) { |
| 113 } | 117 } |
| 114 | 118 |
| 115 } // namespace der | 119 } // namespace der |
| 116 | 120 |
| 117 } // namespace net | 121 } // namespace net |
| OLD | NEW |