]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Move strToAuther out for clarity
authorSergey Matveev <stargrave@stargrave.org>
Tue, 3 Dec 2019 17:18:32 +0000 (20:18 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 3 Dec 2019 17:18:40 +0000 (20:18 +0300)
gocheese.go
passwd.go

index 08f9d8eb0d7ae878411d5688c210184285491711..bdb6ead659d35082a32eb7f52fb8b07ff8395ec2 100644 (file)
@@ -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 {
index 852192f8b7ea898cb54d7ea3a4e912f884e13bc9..6fb75f57a192702bcc793495a9c44de708d163af 100644 (file)
--- a/passwd.go
+++ b/passwd.go
@@ -19,11 +19,31 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 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 {