diff --git a/register/miniosha256/multihash_miniosha256.go b/register/miniosha256/multihash_miniosha256.go deleted file mode 100644 index 2b6c224..0000000 --- a/register/miniosha256/multihash_miniosha256.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -This package has no purpose except to perform registration of multihashes. - -It is meant to be used as a side-effecting import, e.g. - - import ( - _ "github.com/multiformats/go-multihash/register/miniosha256" - ) - -This package registers alternative implementations for sha2-256, using -the github.com/minio/sha256-simd library. -*/ -package miniosha256 - -import ( - "github.com/minio/sha256-simd" - - multihash "github.com/multiformats/go-multihash/core" -) - -func init() { - multihash.Register(multihash.SHA2_256, sha256.New) -} diff --git a/register/miniosha256/post_go1.21.go b/register/miniosha256/post_go1.21.go new file mode 100644 index 0000000..0a35411 --- /dev/null +++ b/register/miniosha256/post_go1.21.go @@ -0,0 +1,22 @@ +//go:build go1.21 + +// This package has no purpose except to perform registration of multihashes. +// +// It is meant to be used as a side-effecting import, e.g. +// +// import ( +// _ "github.com/multiformats/go-multihash/register/miniosha256" +// ) +// +// This package registers alternative implementations for sha2-256, using +// the github.com/minio/sha256-simd library for go1.20 and bellow. Go 1.21 and +// later fallback to [github.com/multiformats/go-multihash/register/sha256]. +// +// Deprecated: please switch to [github.com/multiformats/go-multihash/register/sha256] +// as of go1.21 the go std has a SHANI implementation that is just as fast. See https://go.dev/issue/50543. +// This will be removed shortly after go1.22 is released. +package miniosha256 + +import ( + _ "github.com/multiformats/go-multihash/register/sha256" +) diff --git a/register/miniosha256/pre_go1_21.go b/register/miniosha256/pre_go1_21.go new file mode 100644 index 0000000..270861b --- /dev/null +++ b/register/miniosha256/pre_go1_21.go @@ -0,0 +1,29 @@ +//go:build !go1.21 + +// This package has no purpose except to perform registration of multihashes. +// +// It is meant to be used as a side-effecting import, e.g. +// +// import ( +// _ "github.com/multiformats/go-multihash/register/miniosha256" +// ) +// +// This package registers alternative implementations for sha2-256, using +// the github.com/minio/sha256-simd library for go1.20 and bellow. Go 1.21 and +// later fallback to [github.com/multiformats/go-multihash/register/sha256]. +// +// Note if you are using go1.21 or above this package is deprecated in favor of +// [github.com/multiformats/go-multihash/register/sha256] because as of go1.21 +// the go std has a SHANI implementation that is just as fast. See https://go.dev/issue/50543. +// This will be removed shortly after go1.22 is released. +package miniosha256 + +import ( + "github.com/minio/sha256-simd" + + multihash "github.com/multiformats/go-multihash/core" +) + +func init() { + multihash.Register(multihash.SHA2_256, sha256.New) +} diff --git a/register/sha256/sha256.go b/register/sha256/sha256.go new file mode 100644 index 0000000..b5f30b2 --- /dev/null +++ b/register/sha256/sha256.go @@ -0,0 +1,21 @@ +// This package has no purpose except to perform registration of multihashes. +// +// It is meant to be used as a side-effecting import, e.g. +// +// import ( +// _ "github.com/multiformats/go-multihash/register/sha256" +// ) +// +// This package an implementation of sha256 using the go std, this is recomanded +// if you are using go1.21 or above. +package sha256 + +import ( + "crypto/sha256" + + multihash "github.com/multiformats/go-multihash/core" +) + +func init() { + multihash.Register(multihash.SHA2_256, sha256.New) +} diff --git a/version.json b/version.json index 88bcb86..65b4a15 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.2.1" + "version": "v0.2.2" }