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.
5 #include "base/logging.h"
6 #include "net/der/input.h"
12 Input::Input() : data_(nullptr), len_(0) {
14 Input::Input(const uint8_t* data
, size_t len
) : data_(data
), len_(len
) {
16 Input::Input(const std::string
& s
)
17 : data_(reinterpret_cast<const uint8_t*>(s
.data())), len_(s
.size()) {
20 ByteReader::ByteReader(const Input
& in
)
21 : data_(in
.UnsafeData()), len_(in
.Length()) {
24 bool ByteReader::ReadByte(uint8_t* byte_p
) {
32 bool ByteReader::ReadBytes(size_t len
, Input
* out
) {
35 *out
= Input(data_
, len
);
40 // Returns whether there is any more data to be read.
41 bool ByteReader::HasMore() {
45 Mark
ByteReader::NewMark() {
49 bool ByteReader::AdvanceToMark(Mark mark
) {
50 if (mark
.ptr_
< data_
)
52 // mark.ptr_ >= data_, so no concern of integer underflow here.
53 size_t advance_len
= mark
.ptr_
- data_
;
54 if (advance_len
> len_
)
60 bool ByteReader::ReadToMark(Mark mark
, Input
* out
) {
61 if (mark
.ptr_
< data_
)
63 // mark.ptr_ >= data_, so no concern of integer underflow here.
64 size_t len
= mark
.ptr_
- data_
;
65 return ReadBytes(len
, out
);
68 void ByteReader::Advance(size_t len
) {
74 Mark
Mark::NullMark() {
78 bool Mark::IsEmpty() {
79 return ptr_
== nullptr;
82 Mark::Mark(const uint8_t* ptr
) : ptr_(ptr
) {
85 Mark::Mark() : ptr_(nullptr) {