refactor(tvix/nar-bridge): move pkg/server to pkg/http

This is only dealing with the HTTP interface.

Change-Id: I011b624fd9f11ea96231b92fea1166c118a219f2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9535
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
This commit is contained in:
Florian Klink 2023-10-03 14:49:18 +03:00 committed by flokli
parent 0353108e99
commit 28d1b9c01d
7 changed files with 8 additions and 8 deletions

View file

@ -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
}