refactor(tvix/nar-bridge): use mh.SHA2_256
As correctly mentioned in https://cl.tvl.fyi/c/depot/+/9652/comment/03b9b96e_bbb337fd/, we shouldn't be using these magic constants, but pull them from where they're defined. This already is a dependency of go-nix, and pkg/pathinfosvc/server.go, so no changes in go.mod. Change-Id: I0cc41ce040fcbddf4b6171417bc9b0de55af4991 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9653 Tested-by: BuildkiteCI Reviewed-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
fb04645b0d
commit
155ab77cff
2 changed files with 5 additions and 2 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
castorev1pb "code.tvl.fyi/tvix/castore/protos"
|
castorev1pb "code.tvl.fyi/tvix/castore/protos"
|
||||||
"code.tvl.fyi/tvix/nar-bridge/pkg/importer"
|
"code.tvl.fyi/tvix/nar-bridge/pkg/importer"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
mh "github.com/multiformats/go-multihash/core"
|
||||||
nixhash "github.com/nix-community/go-nix/pkg/hash"
|
nixhash "github.com/nix-community/go-nix/pkg/hash"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -101,7 +102,7 @@ func registerNarPut(s *Server) {
|
||||||
|
|
||||||
// Compare the nar hash specified in the URL with the one that has been
|
// Compare the nar hash specified in the URL with the one that has been
|
||||||
// calculated while processing the NAR file.
|
// calculated while processing the NAR file.
|
||||||
narHash, err := nixhash.FromHashTypeAndDigest(0x12, narSha256)
|
narHash, err := nixhash.FromHashTypeAndDigest(mh.SHA2_256, narSha256)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("must parse nixbase32")
|
panic("must parse nixbase32")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
storev1pb "code.tvl.fyi/tvix/store/protos"
|
storev1pb "code.tvl.fyi/tvix/store/protos"
|
||||||
|
mh "github.com/multiformats/go-multihash/core"
|
||||||
nixhash "github.com/nix-community/go-nix/pkg/hash"
|
nixhash "github.com/nix-community/go-nix/pkg/hash"
|
||||||
|
|
||||||
"github.com/nix-community/go-nix/pkg/narinfo"
|
"github.com/nix-community/go-nix/pkg/narinfo"
|
||||||
"github.com/nix-community/go-nix/pkg/narinfo/signature"
|
"github.com/nix-community/go-nix/pkg/narinfo/signature"
|
||||||
"github.com/nix-community/go-nix/pkg/nixbase32"
|
"github.com/nix-community/go-nix/pkg/nixbase32"
|
||||||
|
@ -30,7 +32,7 @@ func ToNixNarInfo(p *storev1pb.PathInfo) (*narinfo.NarInfo, error) {
|
||||||
|
|
||||||
// produce nixhash for the narsha256.
|
// produce nixhash for the narsha256.
|
||||||
narHash, err := nixhash.FromHashTypeAndDigest(
|
narHash, err := nixhash.FromHashTypeAndDigest(
|
||||||
0x12, // SHA2_256
|
mh.SHA2_256,
|
||||||
p.GetNarinfo().GetNarSha256(),
|
p.GetNarinfo().GetNarSha256(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue