parseUnknown parses a blobref where the digest type isn't known to this server. e.g. ("foo-ababab")
(digest, hex string)
| 320 | // parseUnknown parses a blobref where the digest type isn't known to this server. |
| 321 | // e.g. ("foo-ababab") |
| 322 | func parseUnknown(digest, hex string) (ref Ref, ok bool) { |
| 323 | if !validDigestName(digest) { |
| 324 | return |
| 325 | } |
| 326 | |
| 327 | // TODO: remove this short hack and don't allow odd numbers of hex digits. |
| 328 | odd := false |
| 329 | if len(hex)%2 != 0 { |
| 330 | hex += "0" |
| 331 | odd = true |
| 332 | } |
| 333 | |
| 334 | if len(hex) < 2 || len(hex)%2 != 0 || len(hex) > maxOtherDigestLen*2 { |
| 335 | return |
| 336 | } |
| 337 | o := otherDigest{ |
| 338 | name: digest, |
| 339 | sumLen: len(hex) / 2, |
| 340 | odd: odd, |
| 341 | } |
| 342 | bad := false |
| 343 | for i := 0; i < len(hex); i += 2 { |
| 344 | o.sum[i/2] = hexVal(hex[i], &bad)<<4 | hexVal(hex[i+1], &bad) |
| 345 | } |
| 346 | if bad { |
| 347 | return |
| 348 | } |
| 349 | return Ref{o}, true |
| 350 | } |
| 351 | |
| 352 | func sha1FromBinary(b []byte) digestType { |
| 353 | var d sha1Digest |
no test coverage detected