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