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 #include <openssl/base.h> 8 9 namespace bssl::der { 10 AsString() const11std::string Input::AsString() const { return std::string(AsStringView()); } 12 operator ==(Input lhs,Input rhs)13bool operator==(Input lhs, Input rhs) { 14 return MakeConstSpan(lhs) == MakeConstSpan(rhs); 15 } 16 operator !=(Input lhs,Input rhs)17bool operator!=(Input lhs, Input rhs) { return !(lhs == rhs); } 18 ByteReader(Input in)19ByteReader::ByteReader(Input in) : data_(in) {} 20 ReadByte(uint8_t * byte_p)21bool ByteReader::ReadByte(uint8_t *byte_p) { 22 if (!HasMore()) { 23 return false; 24 } 25 *byte_p = data_[0]; 26 Advance(1); 27 return true; 28 } 29 ReadBytes(size_t len,Input * out)30bool ByteReader::ReadBytes(size_t len, Input *out) { 31 if (len > data_.size()) { 32 return false; 33 } 34 *out = Input(data_.first(len)); 35 Advance(len); 36 return true; 37 } 38 39 // Returns whether there is any more data to be read. HasMore()40bool ByteReader::HasMore() { return !data_.empty(); } 41 Advance(size_t len)42void ByteReader::Advance(size_t len) { 43 BSSL_CHECK(len <= data_.size()); 44 data_ = data_.subspan(len); 45 } 46 47 } // namespace bssl::der 48