Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: net/der/parser.h

Issue 1248043002: Add functions for DER parsing a BIT STRING. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nharper's comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DER_PARSER_H_ 5 #ifndef NET_DER_PARSER_H_
6 #define NET_DER_PARSER_H_ 6 #define NET_DER_PARSER_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "net/base/net_export.h" 10 #include "net/base/net_export.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 bool ReadConstructed(Tag tag, Parser* out) WARN_UNUSED_RESULT; 138 bool ReadConstructed(Tag tag, Parser* out) WARN_UNUSED_RESULT;
139 139
140 // A more specific form of ReadConstructed that expects the current tag 140 // A more specific form of ReadConstructed that expects the current tag
141 // to be 0x30 (SEQUENCE). 141 // to be 0x30 (SEQUENCE).
142 bool ReadSequence(Parser* out) WARN_UNUSED_RESULT; 142 bool ReadSequence(Parser* out) WARN_UNUSED_RESULT;
143 143
144 // Expects the current tag to be kInteger, and calls ParseUint64 on the 144 // Expects the current tag to be kInteger, and calls ParseUint64 on the
145 // current value. Note that DER-encoded integers are arbitrary precision, 145 // current value. Note that DER-encoded integers are arbitrary precision,
146 // so this method will fail for valid input that represents an integer 146 // so this method will fail for valid input that represents an integer
147 // outside the range of an int64. 147 // outside the range of an int64.
148 //
149 // Note that on failure the Parser is left in an undefined state (the
150 // input may or may not have been advanced).
148 bool ReadUint64(uint64_t* out) WARN_UNUSED_RESULT; 151 bool ReadUint64(uint64_t* out) WARN_UNUSED_RESULT;
149 152
153 // Reads a BIT STRING. On success |bytes| is set to the octet string
154 // containing the bits, and |unused_bits| is set to the number of
155 // bits (in the range 0-7) that are unused.
davidben 2015/07/27 20:19:59 Probably add: The bits are ordered within each oct
eroman 2015/07/27 21:19:23 Done.
156 //
157 // Note that on failure the Parser is left in an undefined state (the
158 // input may or may not have been advanced).
159 bool ReadBitString(Input* bytes, uint8_t* unused_bits) WARN_UNUSED_RESULT;
160
161 // Same as ReadBitString() except it will only succeed when the number of
162 // bits in the bit string is a multiple of 8. In other words, there can be
163 // no unused bits in the octet string |*bytes|.
164 bool ReadBitStringNoUnusedBits(Input* bytes) WARN_UNUSED_RESULT;
165
150 // Lower level methods. The previous methods couple reading data from the 166 // Lower level methods. The previous methods couple reading data from the
151 // input with advancing the Parser's internal pointer to the next TLV; these 167 // input with advancing the Parser's internal pointer to the next TLV; these
152 // lower level methods decouple those two steps into methods that read from 168 // lower level methods decouple those two steps into methods that read from
153 // the current TLV and a method that advances the internal pointer to the 169 // the current TLV and a method that advances the internal pointer to the
154 // next TLV. 170 // next TLV.
155 171
156 // Reads the current TLV from the input, putting the tag in |tag| and the raw 172 // Reads the current TLV from the input, putting the tag in |tag| and the raw
157 // value in |out|, but does not advance the input. Returns true if the tag 173 // value in |out|, but does not advance the input. Returns true if the tag
158 // and length are successfully read and the output exists. 174 // and length are successfully read and the output exists.
159 bool PeekTagAndValue(Tag* tag, Input* out) WARN_UNUSED_RESULT; 175 bool PeekTagAndValue(Tag* tag, Input* out) WARN_UNUSED_RESULT;
160 176
161 // Advances the input to the next TLV. This method only needs to be called 177 // Advances the input to the next TLV. This method only needs to be called
162 // after PeekTagAndValue; all other methods will advance the input if they 178 // after PeekTagAndValue; all other methods will advance the input if they
163 // read something. 179 // read something.
164 bool Advance(); 180 bool Advance();
165 181
166 private: 182 private:
167 ByteReader input_; 183 ByteReader input_;
168 Mark advance_mark_; 184 Mark advance_mark_;
169 185
170 DISALLOW_COPY(Parser); 186 DISALLOW_COPY(Parser);
171 }; 187 };
172 188
173 } // namespace der 189 } // namespace der
174 190
175 } // namespace net 191 } // namespace net
176 192
177 #endif // NET_DER_PARSER_H_ 193 #endif // NET_DER_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698