Add salt & checksum checking

This commit is contained in:
Ben Johnson
2020-12-21 16:59:15 -07:00
parent f4819efbeb
commit 2bbe5d91bf
2 changed files with 326 additions and 112 deletions

View File

@@ -1,12 +1,25 @@
package litestream
import (
"encoding/binary"
"encoding/hex"
"strings"
_ "github.com/mattn/go-sqlite3"
)
// Checksum computes a running SQLite checksum over a byte slice.
func Checksum(bo binary.ByteOrder, s0, s1 uint32, b []byte) (uint32, uint32) {
assert(len(b)%8 == 0, "misaligned checksum byte slice")
// Iterate over 8-byte units and compute checksum.
for i := 0; i < len(b); i += 8 {
s0 += bo.Uint32(b[i:]) + s1
s1 += bo.Uint32(b[i+4:]) + s0
}
return s0, s1
}
// HexDump returns hexdump output but with duplicate lines removed.
func HexDump(b []byte) string {
const prefixN = len("00000000")