Use strings.Builder in Fingerprint
This commit is contained in:
parent
7f0b1fa8a1
commit
34ae2a9066
@ -7,6 +7,7 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
9
fs.go
9
fs.go
@ -5,7 +5,6 @@ import (
|
||||
"mime"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -25,14 +24,14 @@ type fsHandler struct {
|
||||
}
|
||||
|
||||
func (fsh fsHandler) Respond(w *ResponseWriter, r *Request) {
|
||||
path := path.Clean(r.URL.Path)
|
||||
f, err := fsh.Open(path)
|
||||
p := path.Clean(r.URL.Path)
|
||||
f, err := fsh.Open(p)
|
||||
if err != nil {
|
||||
w.WriteStatus(StatusNotFound)
|
||||
return
|
||||
}
|
||||
// Detect mimetype
|
||||
ext := filepath.Ext(path)
|
||||
ext := path.Ext(p)
|
||||
mimetype := mime.TypeByExtension(ext)
|
||||
w.SetMimetype(mimetype)
|
||||
// Copy file to response writer
|
||||
@ -71,7 +70,7 @@ func ServeFile(w *ResponseWriter, fs FS, name string) {
|
||||
return
|
||||
}
|
||||
// Detect mimetype
|
||||
ext := filepath.Ext(name)
|
||||
ext := path.Ext(name)
|
||||
mimetype := mime.TypeByExtension(ext)
|
||||
w.SetMimetype(mimetype)
|
||||
// Copy file to response writer
|
||||
|
9
tofu.go
9
tofu.go
@ -2,7 +2,6 @@ package gemini
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/sha512"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
@ -162,14 +161,14 @@ func appendKnownHost(w io.Writer, hostname string, c certInfo) (int, error) {
|
||||
// Fingerprint returns the SHA-512 fingerprint of the provided certificate.
|
||||
func Fingerprint(cert *x509.Certificate) string {
|
||||
sum512 := sha512.Sum512(cert.Raw)
|
||||
var buf bytes.Buffer
|
||||
var b strings.Builder
|
||||
for i, f := range sum512 {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(&buf, ":")
|
||||
b.WriteByte(':')
|
||||
}
|
||||
fmt.Fprintf(&buf, "%02X", f)
|
||||
fmt.Fprintf(&b, "%02X", f)
|
||||
}
|
||||
return buf.String()
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// defaultKnownHostsPath returns the default known_hosts path.
|
||||
|
Loading…
Reference in New Issue
Block a user