MCPcopy Create free account
hub / github.com/blobcache/blobcache / CheckBlob

Function CheckBlob

src/blobcache/blobcache.go:419–436  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

417// CheckBlob checks that the data matches the expected CID.
418// If there is a problem, it returns an ErrBadData.
419func 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}

Callers 1

GetFunction · 0.92

Calls 1

HashMethod · 0.65

Tested by

no test coverage detected