MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / calcSha256Hash

Method calcSha256Hash

testutil/image_hash.go:258–279  ·  view source on GitHub ↗

calcSha256Hash calculates the SHA-256 hash for the given image data buffer

(buf []byte)

Source from the content-addressed store, hash-verified

256
257// calcSha256Hash calculates the SHA-256 hash for the given image data buffer
258func (h *ImageHash) calcSha256Hash(buf []byte) error {
259 var rgbaData unsafe.Pointer
260 var rgbaSize C.size_t
261
262 defer func() {
263 if rgbaData != nil {
264 C.free(rgbaData)
265 }
266 }()
267
268 // Load RGBA pixels using VIPS
269 bufPtr := unsafe.Pointer(unsafe.SliceData(buf))
270 readErr := C.vips_rgba_image_data(bufPtr, C.size_t(len(buf)), &rgbaData, &rgbaSize)
271 if readErr != 0 {
272 return fmt.Errorf("failed to convert image to RGBA for hashing: %s", vipsErrorMessage())
273 }
274
275 // Calculate SHA-256 hash
276 h.sha256Hash = sha256.Sum256(unsafe.Slice((*byte)(rgbaData), int(rgbaSize)))
277
278 return nil
279}

Callers 1

NewImageHashFromBytesFunction · 0.95

Calls 3

vipsErrorMessageFunction · 0.85
freeMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected