Removes placeholder message string for aria role option
[chromium-blink-merge.git] / net / der / input.cc
blob45edfdcca67fde5ad002f151d6f2deb7e39c0870
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 <string.h>
7 #include "base/logging.h"
8 #include "net/der/input.h"
10 namespace net {
12 namespace der {
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_)
22 return false;
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) {
31 if (!HasMore())
32 return false;
33 *byte_p = *data_;
34 Advance(1);
35 return true;
38 bool ByteReader::ReadBytes(size_t len, Input* out) {
39 if (len > len_)
40 return false;
41 *out = Input(data_, len);
42 Advance(len);
43 return true;
46 // Returns whether there is any more data to be read.
47 bool ByteReader::HasMore() {
48 return len_ > 0;
51 Mark ByteReader::NewMark() {
52 return Mark(data_);
55 bool ByteReader::AdvanceToMark(Mark mark) {
56 if (mark.ptr_ < data_)
57 return false;
58 // mark.ptr_ >= data_, so no concern of integer underflow here.
59 size_t advance_len = mark.ptr_ - data_;
60 if (advance_len > len_)
61 return false;
62 Advance(advance_len);
63 return true;
66 bool ByteReader::ReadToMark(Mark mark, Input* out) {
67 if (mark.ptr_ < data_)
68 return false;
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) {
75 CHECK_LE(len, len_);
76 data_ += len;
77 len_ -= len;
80 Mark Mark::NullMark() {
81 return Mark();
84 bool Mark::IsEmpty() {
85 return ptr_ == nullptr;
88 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) {
91 Mark::Mark() : ptr_(nullptr) {
94 } // namespace der
96 } // namespace net