func MustNewKeyPair() *sf.KeyPair { kp, err := sf.NewKeyPair() if err != nil { panic(err) } return &kp }
func (s *vaultSuite) TestVault(c *gc.C) { secKey, err := sf.NewSecretKey() v := sfbolt.NewVault(s.db, secKey) _, err = v.Current() c.Assert(err, gc.ErrorMatches, "empty vault") var kp *sf.KeyPair kp1, err := sf.NewKeyPair() c.Assert(err, gc.IsNil) err = v.Put(&kp1) c.Assert(err, gc.IsNil) kp, err = v.Get(kp1.PublicKey) c.Assert(err, gc.IsNil) c.Assert(kp, gc.DeepEquals, &kp1) kp, err = v.Current() c.Assert(err, gc.IsNil) c.Assert(kp, gc.DeepEquals, &kp1) kp2, err := sf.NewKeyPair() c.Assert(err, gc.IsNil) err = v.Put(&kp2) c.Assert(err, gc.IsNil) kp, err = v.Get(kp2.PublicKey) c.Assert(err, gc.IsNil) c.Assert(kp, gc.DeepEquals, &kp2) kp, err = v.Current() c.Assert(err, gc.IsNil) c.Assert(kp, gc.DeepEquals, &kp2) // Can still look up prior key pair by public key. kp, err = v.Get(kp1.PublicKey) c.Assert(err, gc.IsNil) c.Assert(kp, gc.DeepEquals, &kp1) }
func newKeyPair() (*sf.KeyPair, error) { f, err := os.OpenFile(*keypairFlag, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return nil, errgo.Mask(err) } defer f.Close() kp, err := sf.NewKeyPair() _, err = f.Write(kp.PublicKey[:]) if err != nil { return nil, errgo.Mask(err) } _, err = f.Write(kp.PrivateKey[:]) if err != nil { return nil, errgo.Mask(err) } return &kp, nil }
func addrCreate() error { vault, err := newVault() if err != nil { return errgo.Mask(err) } keyPair, err := sf.NewKeyPair() if err != nil { return errgo.Mask(err) } err = vault.Put(&keyPair) if err != nil { return errgo.Mask(err) } contacts, err := newContacts() if err != nil { return err } err = contacts.Put("me", keyPair.PublicKey) return errgo.Mask(err) }