go - "undefined: hmac.Equal" error while hmac.New in the line before this works fine -
i developing web server in go,
@ top have
import ("net/http" "log" "fmt" "encoding/json" "encoding/hex" "time" "math/rand" "crypto/sha256" "crypto/hmac" "strconv" "strings" "github.com/crowdmob/goamz/aws" "github.com/crowdmob/goamz/dynamodb" )
later have
func singsomething(someid string) string { mac := hmac.new(sha256.new, key) mac.write([]byte(id)) b := mac.sum(nil) return hex.encodetostring(b) } func validatesignature(id, signature string) bool { mac := hmac.new(sha256.new, key) mac.write([]byte(id)) expectedmac := mac.sum(nil) signaturemac, err := hex.decodestring(signature) if err != nil { fmt.println("problem in decoding huh!") return false } return hmac.equal(expectedmac,signaturemac)
}
i error when issue go run csserver
/csserver.go:54: undefined: hmac.equal
why? going on? how come hmac.new
fine hmac.equals
not?
please post minimal, complete programs when asking. without that, thing can provide example compiles w/o trouble, ie. undefined hmac.equal
doesn't demonstrate. there must problem elsewhere in code didn't show.
package main import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "fmt" ) func singsomething(someid string) string { mac := hmac.new(sha256.new, []byte{}) mac.write([]byte(someid)) b := mac.sum(nil) return hex.encodetostring(b) } func validatesignature(id, signature string) bool { mac := hmac.new(sha256.new, []byte{}) mac.write([]byte(id)) expectedmac := mac.sum(nil) signaturemac, err := hex.decodestring(signature) if err != nil { fmt.println("problem in decoding huh!") return false } return hmac.equal(expectedmac, signaturemac) } func main() {}
Comments
Post a Comment