Artifact 75b38460fcf09012c653cbee856f07c5a7a3062e8db3dd561b7c40b41b3b399a:
- File
internal/sync/auth.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 1239) [annotate] [blame] [check-ins using]
package sync import ( "crypto/sha1" "encoding/hex" "fmt" "github.com/danmestas/libfossil/simio" "github.com/danmestas/libfossil/internal/xfer" ) // computeLogin produces a LoginCard for the given credentials. // payload is the encoded bytes of all non-login cards (including random comment). func computeLogin(user, password, projectCode string, payload []byte) *xfer.LoginCard { if user == "" { panic("sync.computeLogin: user must not be empty") } if projectCode == "" { panic("sync.computeLogin: projectCode must not be empty") } if payload == nil { panic("sync.computeLogin: payload must not be nil") } nonce := sha1Hex(payload) sharedSecret := sha1Hex([]byte(projectCode + "/" + user + "/" + password)) signature := sha1Hex([]byte(nonce + sharedSecret)) return &xfer.LoginCard{User: user, Nonce: nonce, Signature: signature} } // appendRandomComment appends "# <random-hex>\n" to payload for nonce uniqueness. func appendRandomComment(payload []byte, rng simio.Rand) []byte { rb := make([]byte, 20) rng.Read(rb) comment := fmt.Sprintf("# %s\n", hex.EncodeToString(rb)) return append(payload, []byte(comment)...) } func sha1Hex(data []byte) string { h := sha1.Sum(data) return hex.EncodeToString(h[:]) }