From: Sergey Matveev Date: Tue, 3 Dec 2019 17:18:32 +0000 (+0300) Subject: Move strToAuther out for clarity X-Git-Tag: v2.0.0~17 X-Git-Url: http://www.git.cypherpunks.ru/?p=gocheese.git;a=commitdiff_plain;h=bcfc26f87e27a5d749eeed3194681e8018df4c5b Move strToAuther out for clarity --- diff --git a/gocheese.go b/gocheese.go index 08f9d8e..bdb6ead 100644 --- a/gocheese.go +++ b/gocheese.go @@ -22,7 +22,6 @@ import ( "bytes" "crypto/sha256" "encoding/hex" - "errors" "flag" "fmt" "io" @@ -267,25 +266,6 @@ func servePkg(w http.ResponseWriter, r *http.Request, dir, filename string) { http.ServeFile(w, r, path) } -func strToAuther(verifier string) (string, Auther, error) { - st := strings.SplitN(verifier, "$", 3) - if len(st) != 3 || st[0] != "" { - return "", nil, errors.New("invalid verifier structure") - } - algorithm := st[1] - var auther Auther - var err error - switch algorithm { - case "argon2i": - auther, err = parseArgon2i(st[2]) - case "sha256": - auther, err = parseSHA256(st[2]) - default: - err = errors.New("unknown hashing algorithm") - } - return algorithm, auther, err -} - func serveUpload(w http.ResponseWriter, r *http.Request) { username, password, ok := r.BasicAuth() if !ok { diff --git a/passwd.go b/passwd.go index 852192f..6fb75f5 100644 --- a/passwd.go +++ b/passwd.go @@ -19,11 +19,31 @@ along with this program. If not, see . package main import ( + "errors" "io/ioutil" "log" "strings" ) +func strToAuther(verifier string) (string, Auther, error) { + st := strings.SplitN(verifier, "$", 3) + if len(st) != 3 || st[0] != "" { + return "", nil, errors.New("invalid verifier structure") + } + algorithm := st[1] + var auther Auther + var err error + switch algorithm { + case "argon2i": + auther, err = parseArgon2i(st[2]) + case "sha256": + auther, err = parseSHA256(st[2]) + default: + err = errors.New("unknown hashing algorithm") + } + return algorithm, auther, err +} + func refreshPasswd() { passwd, err := ioutil.ReadFile(*passwdPath) if err != nil {