From 1392913e981ae4edbec6ef39a4d3de44749ad81c Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 14 May 2024 12:35:55 +0200 Subject: chore(tvix/nar-bridge): move to nar-bridge-go Make some space for the rust implementation. Change-Id: I924dc1657be10abe5a11951c3b9de50bae06db19 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11662 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: yuka --- tvix/nar-bridge-go/pkg/http/util.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tvix/nar-bridge-go/pkg/http/util.go (limited to 'tvix/nar-bridge-go/pkg/http/util.go') diff --git a/tvix/nar-bridge-go/pkg/http/util.go b/tvix/nar-bridge-go/pkg/http/util.go new file mode 100644 index 000000000000..60febea1f430 --- /dev/null +++ b/tvix/nar-bridge-go/pkg/http/util.go @@ -0,0 +1,24 @@ +package http + +import ( + "fmt" + nixhash "github.com/nix-community/go-nix/pkg/hash" +) + +// parseNarHashFromUrl parses a nixbase32 string representing a sha256 NarHash +// and returns a nixhash.Hash when it was able to parse, or an error. +func parseNarHashFromUrl(narHashFromUrl string) (*nixhash.Hash, error) { + // peek at the length. If it's 52 characters, assume sha256, + // if it's something else, this is an error. + l := len(narHashFromUrl) + if l != 52 { + return nil, fmt.Errorf("invalid length of narHash: %v", l) + } + + nixHash, err := nixhash.ParseNixBase32("sha256:" + narHashFromUrl) + if err != nil { + return nil, fmt.Errorf("unable to parse nixbase32 hash: %w", err) + } + + return nixHash, nil +} -- cgit 1.4.1