aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
Diffstat (limited to 'account.go')
-rw-r--r--account.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/account.go b/account.go
index 6749bbf..b1312c0 100644
--- a/account.go
+++ b/account.go
@@ -6,6 +6,8 @@ import (
"encoding/base64"
"io"
"net/mail"
+ "os"
+ "path"
"strings"
"github.com/square/go-jose"
@@ -87,3 +89,16 @@ func KeyAuthorization(s Thumber, token string) (string, error) {
}
return token + "." + thumb, nil
}
+
+func (a *Account) Save(fname string) error {
+ if err := os.MkdirAll(path.Dir(fname), 0700); err != nil {
+ return err
+ }
+ flags := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
+ fd, err := os.OpenFile(fname, flags, 0600)
+ if err != nil {
+ return err
+ }
+ defer fd.Close()
+ return SaveKey(fd, a.privKey)
+}