(digestHeaderValue string)
| 132 | } |
| 133 | |
| 134 | func (enc Encoding) parseDigestHeader(digestHeaderValue string) ([]byte, error) { |
| 135 | // TODO: Support multiple digest values (Section 4.3.2 of RFC3230). |
| 136 | chunks := strings.SplitN(digestHeaderValue, "=", 2) |
| 137 | if len(chunks) != 2 { |
| 138 | return nil, fmt.Errorf("mice: cannot parse digest value %q", digestHeaderValue) |
| 139 | } |
| 140 | algorithm, digest := chunks[0], chunks[1] |
| 141 | |
| 142 | if algorithm != enc.ContentEncoding() { |
| 143 | return nil, fmt.Errorf("mice: unsupported digest algorithm %q", algorithm) |
| 144 | } |
| 145 | proof, err := enc.base64Encoding().DecodeString(digest) |
| 146 | if err != nil { |
| 147 | return nil, fmt.Errorf("mice: failed to decode digest value %q: %v", digest, err) |
| 148 | } |
| 149 | if len(proof) != sha256.Size { |
| 150 | return nil, fmt.Errorf("mice: wrong digest length %q", digest) |
| 151 | } |
| 152 | return proof, nil |
| 153 | } |
| 154 | |
| 155 | type decoder struct { |
| 156 | encoding Encoding |
no test coverage detected