1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "input.h" 6 7 BSSL_NAMESPACE_BEGIN 8 namespace der { 9 AsString() const10std::string Input::AsString() const { return std::string(AsStringView()); } 11 operator ==(Input lhs,Input rhs)12bool operator==(Input lhs, Input rhs) { return Span(lhs) == Span(rhs); } 13 operator !=(Input lhs,Input rhs)14bool operator!=(Input lhs, Input rhs) { return !(lhs == rhs); } 15 ByteReader(Input in)16ByteReader::ByteReader(Input in) : data_(in) {} 17 ReadByte(uint8_t * byte_p)18bool ByteReader::ReadByte(uint8_t *byte_p) { 19 if (!HasMore()) { 20 return false; 21 } 22 *byte_p = data_[0]; 23 Advance(1); 24 return true; 25 } 26 ReadBytes(size_t len,Input * out)27bool ByteReader::ReadBytes(size_t len, Input *out) { 28 if (len > data_.size()) { 29 return false; 30 } 31 *out = Input(data_.first(len)); 32 Advance(len); 33 return true; 34 } 35 36 // Returns whether there is any more data to be read. HasMore()37bool ByteReader::HasMore() { return !data_.empty(); } 38 Advance(size_t len)39void ByteReader::Advance(size_t len) { 40 BSSL_CHECK(len <= data_.size()); 41 data_ = data_.subspan(len); 42 } 43 44 } // namespace der 45 BSSL_NAMESPACE_END 46