CheckBlob checks that the data matches the expected CID. If there is a problem, it returns an ErrBadData.
(ha HashAlgo, salt, cid *CID, data []byte)
| 417 | // CheckBlob checks that the data matches the expected CID. |
| 418 | // If there is a problem, it returns an ErrBadData. |
| 419 | func CheckBlob(ha HashAlgo, salt, cid *CID, data []byte) error { |
| 420 | var actualCID CID |
| 421 | if salt == nil { |
| 422 | actualCID = ha.Hash(data) |
| 423 | } else { |
| 424 | hf := ha.KeyedHash |
| 425 | actualCID = hf(salt, data) |
| 426 | } |
| 427 | if *cid != actualCID { |
| 428 | return ErrBadData{ |
| 429 | Salt: salt, |
| 430 | Expected: *cid, |
| 431 | Actual: actualCID, |
| 432 | Len: len(data), |
| 433 | } |
| 434 | } |
| 435 | return nil |
| 436 | } |