Ejemplo n.º 1
0
func writeHC(b *bytes.Buffer, hc *HostConfig, p *sign.Node) error {
	// Node{name, pubkey, x_hat, children}
	if p == nil {
		return errors.New("node does not exist")
	}
	prk, _ := p.PrivKey.MarshalBinary()
	pbk, _ := p.PubKey.MarshalBinary()
	fmt.Fprint(b, "{\"name\":", "\""+p.Name()+"\",")
	fmt.Fprint(b, "\"prikey\":", "\""+string(hex.EncodeToString(prk))+"\",")
	fmt.Fprint(b, "\"pubkey\":", "\""+string(hex.EncodeToString(pbk))+"\",")

	// recursively format children
	fmt.Fprint(b, "\"children\":[")
	i := 0
	for _, n := range p.Children(0) {
		if i != 0 {
			b.WriteString(", ")
		}
		c := hc.Hosts[n.Name()]
		err := writeHC(b, hc, c)
		if err != nil {
			b.WriteString("\"" + n.Name() + "\"")
		}
		i++
	}
	fmt.Fprint(b, "]}")
	return nil
}
Ejemplo n.º 2
0
func traverseTree(p *sign.Node,
	hc *HostConfig,
	f func(*sign.Node, *HostConfig) error) error {
	if err := f(p, hc); err != nil {
		return err
	}
	for _, cn := range p.Children(0) {
		c := hc.Hosts[cn.Name()]
		err := traverseTree(c, hc, f)
		if err != nil {
			return err
		}
	}
	return nil
}