示例#1
0
func DoTestKeyRing() {
	var keyRing keys.KeyRing
	const (
		owner = uint32(1)
		kid   = uint(2)
		view  = uint(3)
		name  = "Bronze key"
	)
	DoTestCheck("DoTestKeyRing initial empty", len(keyRing) == 0)
	DoTestCheck("DoTestKeyRing not found", keyRing.Test(owner, kid) == false)
	key1 := keys.Make(owner, kid, name, view)
	keyRing = keyRing.Add(key1)
	DoTestCheck("DoTestKeyRing found after add 1", keyRing.Test(owner, kid))
	key2 := keys.Make(owner+1, kid, name, view)
	keyRing = keyRing.Add(key2)
	DoTestCheck("DoTestKeyRing found again after add 2", keyRing.Test(owner, kid))
	DoTestCheck("DoTestKeyRing found after add 2", keyRing.Test(owner+1, kid))
}
func ActivatorMessageAddKey_WLu(recepients []quadtree.Object, owner uint32, modifier string, name string) {
	f := func(up *user) {
		// The expected modifier is: "A,B", where A is the key id and B is the view
		args := strings.SplitN(modifier, ",", 2)
		if len(args) != 2 {
			if *verboseFlag > 0 {
				log.Println("Bad key", args)
			}
			return
		}
		keyId, err1 := strconv.ParseUint(args[0], 10, 0)
		viewId, err2 := strconv.ParseUint(args[1], 10, 0)
		if err1 == nil && err2 == nil {
			key := keys.Make(owner, uint(keyId), name, uint(viewId))
			up.Lock()
			up.pl.Keys = up.pl.Keys.Add(key)
			up.Unlock()
		} else {
			log.Println("Bad modifier", modifier, err1, err2)
		}
	}
	ActivatorIterator(f, recepients)
}