How to use 'Master' interface in 'ibe' package?

I’m trying to generate private key using the Extract() in the Master interface of the ibe package, here’s the link of the package,“https://godoc.org/v.io/x/lib/ibe#Master”. In the package, the input of Extract is id, and consist of {0,1}*, so I convert Mac id to binary string first, and then use the binary string to generate correspond private key. My code is like this.

package main`

import (
	"fmt"
	"v.io/x/lib/ibe"
)

var Macid = "00055DNEFF"
var id string

type Params struct {
	params ibe.Params
}
type Privatekey struct {
	params Params
	keys   ibe.PrivateKey
}
type Root struct {
	master ibe.Master
}

func stringToBin(Macid string) (id string) {
	for _, c := range Macid {
		id = fmt.Sprintf("%s%b", id, c)
	}
	return id
}

func (r *Root) ExtractPK(id string) ibeKey {
	ibeKey, err := r.master.Extract(id)
	return ibeKey

}

func main() {
	fmt.Println("MacID is " + Macid + ", public key is" + stringToBin(Macid) + ", private key is" + ExtractPK(stringToBin(Macid)))

}

But I always got errors.

xuJennys-MacBook-Pro:pkg ChunjieXu$ go build pkg.go
command-line-arguments
./pkg.go:29: undefined: ibeKey
./pkg.go:36: undefined: ExtractPK

I’m all new to go, and I have read the tour of go, but I couldn’t get it. Can anyone help me with this? Thank you so much.

xuJennys-MacBook-Pro:pkg ChunjieXu$ go build pkg.go

This is not an error, but a better practice is to call go build without writing down the individual go files. It will find all the buildable (e.g., not test) go files in the current directory and compile them together.

./pkg.go:29: undefined: ibeKey

The offending line:

func (r *Root) ExtractPK(id string) ibeKey {

The compiler does not know what ibeKey is. From reading the function body, I think ibe.PrivateKey is what you meant. The compiler needs a type, not a variable name.

./pkg.go:36: undefined: ExtractPK

I think you mean to call func (r *Root) ExtractPK(id string) ibeKey. This is a method on Root and so needs to be called from a variable of type Root. For example:

r := Root{}
key := r.ExtractPK(stringToBin(Macid))

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.