/src/boringssl/pki/input.cc
Line | Count | Source |
1 | | // Copyright 2015 The Chromium Authors |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "input.h" |
16 | | |
17 | | BSSL_NAMESPACE_BEGIN |
18 | | namespace der { |
19 | | |
20 | 35.2k | bool operator==(Input lhs, Input rhs) { return Span(lhs) == Span(rhs); } |
21 | | |
22 | 790 | bool operator!=(Input lhs, Input rhs) { return !(lhs == rhs); } |
23 | | |
24 | 26.5k | ByteReader::ByteReader(Input in) : data_(in) {} |
25 | | |
26 | 204k | bool ByteReader::ReadByte(uint8_t *byte_p) { |
27 | 204k | if (!HasMore()) { |
28 | 3.61k | return false; |
29 | 3.61k | } |
30 | 201k | *byte_p = data_[0]; |
31 | 201k | Advance(1); |
32 | 201k | return true; |
33 | 204k | } |
34 | | |
35 | 3.60k | bool ByteReader::ReadBytes(size_t len, Input *out) { |
36 | 3.60k | if (len > data_.size()) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 3.60k | *out = Input(data_.first(len)); |
40 | 3.60k | Advance(len); |
41 | 3.60k | return true; |
42 | 3.60k | } |
43 | | |
44 | | // Returns whether there is any more data to be read. |
45 | 217k | bool ByteReader::HasMore() { return !data_.empty(); } |
46 | | |
47 | 204k | void ByteReader::Advance(size_t len) { |
48 | 204k | BSSL_CHECK(len <= data_.size()); |
49 | 204k | data_ = data_.subspan(len); |
50 | 204k | } |
51 | | |
52 | | } // namespace der |
53 | | BSSL_NAMESPACE_END |