Skip to content

Commit

Permalink
Replace custom readFile function with ioutil.ReadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
mback2k committed Dec 20, 2018
1 parent 0067b5d commit 01097f3
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions dkim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 01097f3

Please sign in to comment.