parseBinary parses as defined in https://httpwg.org/specs/rfc9651.html#parse-binary.
(s *scanner)
| 29 | // parseBinary parses as defined in |
| 30 | // https://httpwg.org/specs/rfc9651.html#parse-binary. |
| 31 | func parseBinary(s *scanner) ([]byte, error) { |
| 32 | if s.eof() || s.data[s.off] != ':' { |
| 33 | return nil, &UnmarshalError{s.off, ErrInvalidBinaryFormat} |
| 34 | } |
| 35 | s.off++ |
| 36 | |
| 37 | start := s.off |
| 38 | |
| 39 | for !s.eof() { |
| 40 | c := s.data[s.off] |
| 41 | if c == ':' { |
| 42 | // base64decode |
| 43 | decoded, err := base64.StdEncoding.DecodeString(s.data[start:s.off]) |
| 44 | if err != nil { |
| 45 | return nil, &UnmarshalError{s.off, err} |
| 46 | } |
| 47 | s.off++ |
| 48 | |
| 49 | return decoded, nil |
| 50 | } |
| 51 | |
| 52 | if !isAlpha(c) && !isDigit(c) && c != '+' && c != '/' && c != '=' { |
| 53 | return nil, &UnmarshalError{s.off, ErrInvalidBinaryFormat} |
| 54 | } |
| 55 | s.off++ |
| 56 | } |
| 57 | |
| 58 | return nil, &UnmarshalError{s.off, ErrInvalidBinaryFormat} |
| 59 | } |
searching dependent graphs…