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 ByteReader::ByteReader(const Input
& in
)
27 : data_(in
.UnsafeData()), len_(in
.Length()) {
30 bool ByteReader::ReadByte(uint8_t* byte_p
) {
38 bool ByteReader::ReadBytes(size_t len
, Input
* out
) {
41 *out
= Input(data_
, len
);
46 // Returns whether there is any more data to be read.
47 bool ByteReader::HasMore() {
51 Mark
ByteReader::NewMark() {
55 bool ByteReader::AdvanceToMark(Mark mark
) {
56 if (mark
.ptr_
< data_
)
58 // mark.ptr_ >= data_, so no concern of integer underflow here.
59 size_t advance_len
= mark
.ptr_
- data_
;
60 if (advance_len
> len_
)
66 bool ByteReader::ReadToMark(Mark mark
, Input
* out
) {
67 if (mark
.ptr_
< data_
)
69 // mark.ptr_ >= data_, so no concern of integer underflow here.
70 size_t len
= mark
.ptr_
- data_
;
71 return ReadBytes(len
, out
);
74 void ByteReader::Advance(size_t len
) {
80 Mark
Mark::NullMark() {
84 bool Mark::IsEmpty() {
85 return ptr_
== nullptr;
88 Mark::Mark(const uint8_t* ptr
) : ptr_(ptr
) {
91 Mark::Mark() : ptr_(nullptr) {