xref: /aosp_15_r20/external/cronet/third_party/boringssl/src/pki/input.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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() const11 std::string Input::AsString() const { return std::string(AsStringView()); }
12 
operator ==(Input lhs,Input rhs)13 bool operator==(Input lhs, Input rhs) {
14   return MakeConstSpan(lhs) == MakeConstSpan(rhs);
15 }
16 
operator !=(Input lhs,Input rhs)17 bool operator!=(Input lhs, Input rhs) { return !(lhs == rhs); }
18 
ByteReader(Input in)19 ByteReader::ByteReader(Input in) : data_(in) {}
20 
ReadByte(uint8_t * byte_p)21 bool 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)30 bool 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()40 bool ByteReader::HasMore() { return !data_.empty(); }
41 
Advance(size_t len)42 void ByteReader::Advance(size_t len) {
43   BSSL_CHECK(len <= data_.size());
44   data_ = data_.subspan(len);
45 }
46 
47 }  // namespace bssl::der
48