MCPcopy Create free account
hub / github.com/WICG/webpackage / parseByteSequence

Method parseByteSequence

go/signedexchange/structuredheader/parser.go:289–314  ·  view source on GitHub ↗

https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.11

()

Source from the content-addressed store, hash-verified

287
288// https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.11
289func (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
316func isDigit(c byte) bool {
317 return c >= '0' && c <= '9'

Callers 2

TestParseByteSequenceFunction · 0.95
parseItemMethod · 0.95

Calls 3

isEmptyMethod · 0.95
consumeCharMethod · 0.95
getStringMethod · 0.95

Tested by 1

TestParseByteSequenceFunction · 0.76