()
| 180 | } |
| 181 | |
| 182 | func (d *Decoder) nextHeader() (ret header, err error) { |
| 183 | var b byte |
| 184 | b, err = d.readByte() |
| 185 | |
| 186 | ret.class = int(b >> 6) |
| 187 | ret.constructed = b&0x20 == 0x20 |
| 188 | ret.tag = int(b & 0x1f) |
| 189 | |
| 190 | // If the bottom five bits are set, then the tag number is actually base 128 |
| 191 | // encoded afterwards |
| 192 | if ret.tag == 0x1f { |
| 193 | ret.tag, err = d.readBase128Int() |
| 194 | if err != nil { |
| 195 | return |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if b, err = d.readByte(); err != nil { |
| 200 | return |
| 201 | } |
| 202 | |
| 203 | if b&0x80 == 0 { |
| 204 | // The length is encoded in the bottom 7 bits |
| 205 | ret.length = int(b & 0x7f) |
| 206 | } else { |
| 207 | numBytes := int(b & 0x7f) |
| 208 | if numBytes == 0 { |
| 209 | ret.indefinite = true |
| 210 | return |
| 211 | } |
| 212 | |
| 213 | for i := 0; i < numBytes; i++ { |
| 214 | if b, err = d.readByte(); err != nil { |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | if ret.length >= 1<<23 { |
| 219 | // We can't shift ret.length up without |
| 220 | // overflowing. |
| 221 | err = SyntaxError{"length too large"} |
| 222 | return |
| 223 | } |
| 224 | ret.length <<= 8 |
| 225 | ret.length |= int(b) |
| 226 | if ret.length == 0 { |
| 227 | // is this required by BER? |
| 228 | // DER requires that lengths be minimal. |
| 229 | err = SyntaxError{"superfluous leading zeros in length"} |
| 230 | return |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return |
| 236 | } |
no test coverage detected