• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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() const10 std::string Input::AsString() const { return std::string(AsStringView()); }
11 
operator ==(Input lhs,Input rhs)12 bool operator==(Input lhs, Input rhs) { return Span(lhs) == Span(rhs); }
13 
operator !=(Input lhs,Input rhs)14 bool operator!=(Input lhs, Input rhs) { return !(lhs == rhs); }
15 
ByteReader(Input in)16 ByteReader::ByteReader(Input in) : data_(in) {}
17 
ReadByte(uint8_t * byte_p)18 bool 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)27 bool 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()37 bool ByteReader::HasMore() { return !data_.empty(); }
38 
Advance(size_t len)39 void 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