github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/ext/hash/sha3.go (about)

     1  package hash
     2  
     3  import (
     4  	"crypto"
     5  
     6  	"github.com/ncruces/go-sqlite3"
     7  	"github.com/ncruces/go-sqlite3/internal/util"
     8  )
     9  
    10  func sha3Func(ctx sqlite3.Context, arg ...sqlite3.Value) {
    11  	size := 256
    12  	if len(arg) > 1 {
    13  		size = arg[1].Int()
    14  	}
    15  
    16  	switch size {
    17  	case 224:
    18  		hashFunc(ctx, arg[0], crypto.SHA3_224)
    19  	case 256:
    20  		hashFunc(ctx, arg[0], crypto.SHA3_256)
    21  	case 384:
    22  		hashFunc(ctx, arg[0], crypto.SHA3_384)
    23  	case 512:
    24  		hashFunc(ctx, arg[0], crypto.SHA3_512)
    25  	default:
    26  		ctx.ResultError(util.ErrorString("sha3: size must be 224, 256, 384, 512"))
    27  	}
    28  }