Skip to content

Commit

Permalink
Implemented loading cert from file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan0x44 committed Mar 8, 2023
1 parent 0d261cb commit eb2e481
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# vendor/

dist/

# Other
*.pem
15 changes: 12 additions & 3 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http"
"net/url"
"os"
"strings"
)

Expand All @@ -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) {
Expand Down

0 comments on commit eb2e481

Please sign in to comment.