aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-31 01:24:02 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-31 01:24:02 +0100
commitf7a6acda0e7d04c3fd98e72c6089ba4cfad74ddf (patch)
tree13d089204bd0d5b22208185ba75429a7a01292b8 /account.go
parentf1387fc588b5943c276770d56ec7e1cef3cecaa1 (diff)
Encapsulate desire
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)
+}