From 01097f30d5175267bd5650c8d2228744e2143ebf Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Thu, 20 Dec 2018 19:19:55 +0100 Subject: [PATCH] Replace custom readFile function with ioutil.ReadFile --- dkim.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/dkim.go b/dkim.go index 3c52550..1ab6ee1 100644 --- a/dkim.go +++ b/dkim.go @@ -19,32 +19,17 @@ package main import ( - "bytes" "crypto" "crypto/rsa" "crypto/x509" "encoding/pem" "fmt" - "os" + "io/ioutil" "strings" dkim "github.com/emersion/go-dkim" ) -func readFile(filepath string) (*bytes.Buffer, error) { - var b bytes.Buffer - f, err := os.Open(filepath) - if err != nil { - return nil, err - } - defer f.Close() - _, err = b.ReadFrom(f) - if err != nil { - return nil, err - } - return &b, err -} - func loadPrivKey(privkeypath string) (*rsa.PrivateKey, error) { var block *pem.Block privkey := strings.TrimSpace(privkeypath) @@ -54,11 +39,11 @@ func loadPrivKey(privkeypath string) (*rsa.PrivateKey, error) { } else { splits := strings.Split(privkeypath, "\n") filepath := strings.TrimSpace(splits[0]) - b, err := readFile(filepath) + bytes, err := ioutil.ReadFile(filepath) if err != nil { return nil, err } - block, _ = pem.Decode(b.Bytes()) + block, _ = pem.Decode(bytes) } key, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil {