From eb2e4818a2d40880cf7444a17b9023dcc62a1c80 Mon Sep 17 00:00:00 2001 From: Ryan D Date: Wed, 8 Mar 2023 22:09:49 +1100 Subject: [PATCH] Implemented loading cert from file --- .gitignore | 3 +++ cert.go | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5800750..289935b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ # vendor/ dist/ + +# Other +*.pem diff --git a/cert.go b/cert.go index f6131fb..0f2ccb3 100644 --- a/cert.go +++ b/cert.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "net/url" + "os" "strings" ) @@ -28,9 +29,17 @@ func CertLoad(location string) ([]byte, error) { return CertLoadFromFile(location) } -func CertLoadFromFile(path string) (cert []byte, err error) { - // TODO - return nil, fmt.Errorf("loading cert from file is not implemented yet") +func CertLoadFromFile(filename string) (cert []byte, err error) { + file, err := os.Open(filename) + if err != nil { + return nil, fmt.Errorf("cannot open cert file '%s': %s", filename, err) + } + defer file.Close() + cert, err = io.ReadAll(file) + if err != nil { + return nil, fmt.Errorf("cannot read cert file '%s': %s", filename, err) + } + return } func CertLoadFromURL(inURL string) (cert []byte, err error) {