aboutsummaryrefslogtreecommitdiff
path: root/cmd/acme/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/acme/file.go')
-rw-r--r--cmd/acme/file.go23
1 files changed, 10 insertions, 13 deletions
diff --git a/cmd/acme/file.go b/cmd/acme/file.go
index 7c1c6d9..f29345c 100644
--- a/cmd/acme/file.go
+++ b/cmd/acme/file.go
@@ -4,6 +4,7 @@ import (
"crypto"
"crypto/tls"
"crypto/x509"
+ "errors"
"io"
"os"
"path"
@@ -12,15 +13,12 @@ import (
"dim13.org/acme"
)
+var ErrNotFound = errors.New("file not found")
+
func NewFile(fname string, mode os.FileMode) (io.WriteCloser, error) {
err := os.Rename(fname, fname+".bak")
if err != nil {
- switch e := err.(type) {
- case *os.LinkError:
- if e.Err != syscall.ENOENT {
- return nil, err
- }
- default:
+ if e, ok := err.(*os.LinkError); ok && e.Err != syscall.ENOENT {
return nil, err
}
}
@@ -61,14 +59,10 @@ func (d domain) Save(cert tls.Certificate) error {
func (d domain) Load() (tls.Certificate, error) {
crt, err := tls.LoadX509KeyPair(d.CrtFile, d.KeyFile)
if err != nil {
- switch e := err.(type) {
- case *os.PathError:
- if e.Err != syscall.ENOENT {
- return tls.Certificate{}, err
- }
- default:
- return tls.Certificate{}, nil
+ if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
+ err = ErrNotFound
}
+ return tls.Certificate{}, err
}
crt.Leaf, err = x509.ParseCertificate(crt.Certificate[0])
return crt, err
@@ -89,6 +83,9 @@ func (a account) Save(key crypto.PrivateKey) error {
func (a account) Load() (crypto.PrivateKey, error) {
fd, err := os.Open(a.KeyFile)
if err != nil {
+ if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
+ err = ErrNotFound
+ }
return nil, err
}
defer fd.Close()