func (s *Server) AddRootKey(f string) { data, err := keyfile.Read(f) if err != nil { panic(err) } pub, priv, err := tarcrypto.ParseKey(data) if err != nil { panic(err) } s.ServerKeyChain = new(ServerKeyChain) s.ServerKeyChain.PublicKey = pub s.ServerKeyChain.PrivateKey = priv }
/* * External key data format: * 4 byte little-endian integer = length of key data * 1 byte = key type * N bytes = key data, in key-specific format */ func GenerateSource(key []byte) (err error) { pub, _, err := tarcrypto.ParseKey(key) if err != nil { return } k := &KeyFile{} k.Data = append(k.Data, pub.N.Bytes()...) k.Data = append(k.Data, byte(pub.E)) k.Len = len(k.Data) t, err := template.New("crypto_keys_server.c").Parse(templateFile) if err != nil { return } if err = t.Execute(os.Stdout, k); err != nil { return } return }