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) |
| 23 : data_(reinterpret_cast<const uint8_t*>(in.data())), len_(in.length()) {} |
| 24 |
| 25 Input::Input(const std::string* s) : Input(base::StringPiece(*s)) {} |
| 26 |
22 bool Input::Equals(const Input& other) const { | 27 bool Input::Equals(const Input& other) const { |
23 if (len_ != other.len_) | 28 if (len_ != other.len_) |
24 return false; | 29 return false; |
25 return memcmp(data_, other.data_, len_) == 0; | 30 return memcmp(data_, other.data_, len_) == 0; |
26 } | 31 } |
27 | 32 |
28 std::string Input::AsString() const { | 33 std::string Input::AsString() const { |
29 return std::string(reinterpret_cast<const char*>(data_), len_); | 34 return std::string(reinterpret_cast<const char*>(data_), len_); |
30 } | 35 } |
31 | 36 |
| 37 base::StringPiece Input::AsStringPiece() const { |
| 38 return base::StringPiece(reinterpret_cast<const char*>(data_), len_); |
| 39 } |
| 40 |
32 bool operator<(const Input& lhs, const Input& rhs) { | 41 bool operator<(const Input& lhs, const Input& rhs) { |
33 return std::lexicographical_compare( | 42 return std::lexicographical_compare( |
34 lhs.UnsafeData(), lhs.UnsafeData() + lhs.Length(), rhs.UnsafeData(), | 43 lhs.UnsafeData(), lhs.UnsafeData() + lhs.Length(), rhs.UnsafeData(), |
35 rhs.UnsafeData() + rhs.Length()); | 44 rhs.UnsafeData() + rhs.Length()); |
36 } | 45 } |
37 | 46 |
38 ByteReader::ByteReader(const Input& in) | 47 ByteReader::ByteReader(const Input& in) |
39 : data_(in.UnsafeData()), len_(in.Length()) { | 48 : data_(in.UnsafeData()), len_(in.Length()) { |
40 } | 49 } |
41 | 50 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 108 |
100 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) { | 109 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) { |
101 } | 110 } |
102 | 111 |
103 Mark::Mark() : ptr_(nullptr) { | 112 Mark::Mark() : ptr_(nullptr) { |
104 } | 113 } |
105 | 114 |
106 } // namespace der | 115 } // namespace der |
107 | 116 |
108 } // namespace net | 117 } // namespace net |
OLD | NEW |