-Move Serializer from wsprd to veyron/security
-Remove a convenience interface from principal.go.
Change-Id: I30ea685bf6d56b2f825f1b078c968788157888c2
diff --git a/security/principal.go b/security/principal.go
index 8f4906c..f0dba02 100644
--- a/security/principal.go
+++ b/security/principal.go
@@ -76,17 +76,6 @@
return newPersistentPrincipalFromSigner(security.NewInMemoryECDSASigner(key), dir)
}
-// CreateOrOverwritePersistentPrincipal behaves like CreatePersistentPrincipal except that
-// if the provided directory holds any preexisting principal data then the data gets
-// overwritten. Any prexising private key, BlessingRoots and BlessingStore would get lost
-// as a result of calling this function.
-func CreateOrOverwritePersistentPrincipal(dir string, passphrase []byte) (principal security.Principal, err error) {
- if err := removePersistentPrincipal(dir); err != nil {
- return nil, err
- }
- return CreatePersistentPrincipal(dir, passphrase)
-}
-
// InitDefaultBlessings uses the provided principal to create a self blessing for name 'name',
// sets it as default on the principal's BlessingStore and adds it as root to the principal's BlessingRoots.
func InitDefaultBlessings(p security.Principal, name string) error {
@@ -106,16 +95,6 @@
return nil
}
-func removePersistentPrincipal(dir string) error {
- files := []string{privateKeyFile, blessingRootsDataFile, blessingRootsSigFile, blessingStoreDataFile, blessingStoreSigFile}
- for _, f := range files {
- if err := os.Remove(path.Join(dir, f)); err != nil && !os.IsNotExist(err) {
- return err
- }
- }
- return nil
-}
-
func newPersistentPrincipalFromSigner(signer security.Signer, dir string) (security.Principal, error) {
serializationSigner, err := security.CreatePrincipal(signer, nil, nil)
if err != nil {
diff --git a/security/principal_test.go b/security/principal_test.go
index b717f92..06de1ea 100644
--- a/security/principal_test.go
+++ b/security/principal_test.go
@@ -66,14 +66,10 @@
if err != nil {
t.Fatal(err)
}
- p, err = CreatePersistentPrincipal(dir, passphrase)
+ _, err = CreatePersistentPrincipal(dir, passphrase)
if err == nil {
t.Error("CreatePersistentPrincipal passed unexpectedly")
}
- p, err = CreateOrOverwritePersistentPrincipal(dir, passphrase)
- if err != nil {
- t.Errorf("CreateOrOverwritePersistentPrincipal failed unexpectedly: %v", err)
- }
sig, err := p.Sign(message)
if err != nil {
diff --git a/security/serializer_reader_writer.go b/security/serializer_reader_writer.go
new file mode 100644
index 0000000..55248e4
--- /dev/null
+++ b/security/serializer_reader_writer.go
@@ -0,0 +1,16 @@
+package security
+
+import (
+ "io"
+)
+
+// SerializerReaderWriter is a factory for managing the readers and writers used for
+// serialization and deserialization of signed data.
+type SerializerReaderWriter interface {
+ // Readers returns io.ReadCloser for reading serialized data and its
+ // integrity signature.
+ Readers() (data io.ReadCloser, signature io.ReadCloser, err error)
+ // Writers returns io.WriteCloser for writing serialized data and its
+ // integrity signature.
+ Writers() (data io.WriteCloser, signature io.WriteCloser, err error)
+}
diff --git a/tools/principal/main.go b/tools/principal/main.go
index f865365..c05eb12 100644
--- a/tools/principal/main.go
+++ b/tools/principal/main.go
@@ -344,8 +344,8 @@
environment variables for other veyron applications.
The operation fails if the directory already contains a principal. In this case
-the --overwrite flag can be provided to overwrite the existing principal data in
-the directory.
+the --overwrite flag can be provided to clear the directory and write out a
+new principal.
`,
ArgsName: "<directory> <blessing>",
ArgsLong: `
@@ -363,7 +363,10 @@
err error
)
if flagCreateOverwrite {
- p, err = vsecurity.CreateOrOverwritePersistentPrincipal(dir, nil)
+ if err = os.RemoveAll(dir); err != nil {
+ return err
+ }
+ p, err = vsecurity.CreatePersistentPrincipal(dir, nil)
} else {
p, err = vsecurity.CreatePersistentPrincipal(dir, nil)
}