https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.11
()
| 287 | |
| 288 | // https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.11 |
| 289 | func (p *parser) parseByteSequence() ([]byte, error) { |
| 290 | if p.isEmpty() { |
| 291 | return nil, errors.New("structuredheader: byte sequence expected, got EOS") |
| 292 | } |
| 293 | if !p.consumeChar('*') { |
| 294 | return nil, fmt.Errorf("structuredheader: '*' expected, got '%c'", p.input[0]) |
| 295 | } |
| 296 | len := strings.IndexByte(p.input, '*') |
| 297 | if len < 0 { |
| 298 | return nil, errors.New("structuredheader: missing closing '*'") |
| 299 | } |
| 300 | s := p.getString(len) |
| 301 | enc := base64.StdEncoding |
| 302 | if len%4 != 0 { |
| 303 | // Allow unpadded encoding. |
| 304 | enc = base64.RawStdEncoding |
| 305 | } |
| 306 | data, err := enc.DecodeString(s) |
| 307 | if err != nil { |
| 308 | return nil, fmt.Errorf("structuredheader: couldn't decode base64 %q: %v", s, err) |
| 309 | } |
| 310 | if !p.consumeChar('*') { |
| 311 | panic("cannot happen") |
| 312 | } |
| 313 | return data, nil |
| 314 | } |
| 315 | |
| 316 | func isDigit(c byte) bool { |
| 317 | return c >= '0' && c <= '9' |