I am developing a web server in go,
at the top I 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 I 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 get this error when I issue go run CSServer
/CSServer.go:54: undefined: hmac.Equal
Why? What is going on? How come hmac.New
is fine but hmac.Equals
is not?