跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

fletcher64.go

38 行 · 1.1 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package apfs
5
6import (
7 "encoding/binary"
8 "fmt"
9)
10
11const fletcher64Mod = 0xFFFFFFFF
12
13// fletcher64 computes the APFS Fletcher-64 checksum over block[8:].
14func fletcher64(block []byte) uint64 {
15 var sum1, sum2 uint64
16 for i := 8; i+3 < len(block); i += 4 {
17 sum1 = (sum1 + uint64(binary.LittleEndian.Uint32(block[i:]))) % fletcher64Mod
18 sum2 = (sum2 + sum1) % fletcher64Mod
19 }
20 ckLow := fletcher64Mod - ((sum1 + sum2) % fletcher64Mod)
21 ckHigh := fletcher64Mod - ((sum1 + ckLow) % fletcher64Mod)
22 return (ckHigh << 32) | ckLow
23}
24
25// verifyChecksum returns an error if the stored checksum does not match.
26func verifyChecksum(block []byte) error {
27 stored := binary.LittleEndian.Uint64(block[objChecksumOff:])
28 computed := fletcher64(block)
29 if stored != computed {
30 return fmt.Errorf("checksum mismatch: stored %#x, computed %#x", stored, computed)
31 }
32 return nil
33}
34
35// updateChecksum recomputes and stores the Fletcher-64 checksum.
36func updateChecksum(block []byte) {
37 binary.LittleEndian.PutUint64(block[objChecksumOff:], fletcher64(block))
38}