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
3 // found in the LICENSE file.
7 #include "base/logging.h"
8 #include "net/der/input.h"
14 Input::Input() : data_(nullptr), len_(0) {
17 Input::Input(const uint8_t* data
, size_t len
) : data_(data
), len_(len
) {
20 bool Input::Equals(const Input
& other
) const {
21 if (len_
!= other
.len_
)
23 return memcmp(data_
, other
.data_
, len_
) == 0;
26 std::string
Input::AsString() const {
27 return std::string(reinterpret_cast<const char*>(data_
), len_
);
30 ByteReader::ByteReader(const Input
& in
)
31 : data_(in
.UnsafeData()), len_(in
.Length()) {
34 bool ByteReader::ReadByte(uint8_t* byte_p
) {
42 bool ByteReader::ReadBytes(size_t len
, Input
* out
) {
45 *out
= Input(data_
, len
);
50 // Returns whether there is any more data to be read.
51 bool ByteReader::HasMore() {
55 Mark
ByteReader::NewMark() {
59 bool ByteReader::AdvanceToMark(Mark mark
) {
60 if (mark
.ptr_
< data_
)
62 // mark.ptr_ >= data_, so no concern of integer underflow here.
63 size_t advance_len
= mark
.ptr_
- data_
;
64 if (advance_len
> len_
)
70 bool ByteReader::ReadToMark(Mark mark
, Input
* out
) {
71 if (mark
.ptr_
< data_
)
73 // mark.ptr_ >= data_, so no concern of integer underflow here.
74 size_t len
= mark
.ptr_
- data_
;
75 return ReadBytes(len
, out
);
78 void ByteReader::Advance(size_t len
) {
84 Mark
Mark::NullMark() {
88 bool Mark::IsEmpty() {
89 return ptr_
== nullptr;
92 Mark::Mark(const uint8_t* ptr
) : ptr_(ptr
) {
95 Mark::Mark() : ptr_(nullptr) {