Added ServerVerification Functions, Minor Cleanup

This commit is contained in:
Samuel Lorch 2021-09-22 10:11:55 +02:00
parent 8bccb80cb2
commit 43193345fa
6 changed files with 128 additions and 68 deletions

View file

@ -1,7 +1,10 @@
package api
import (
"fmt"
"math/rand"
"strconv"
"strings"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@ -13,3 +16,28 @@ func randStringBytesRmndr(length int) string {
}
return string(b)
}
func checkAuthTokenFormat(authToken string) error {
splitAuthToken := strings.Split(authToken, "|")
if len(splitAuthToken) != 4 {
return fmt.Errorf("Auth Token Has Wrong amount of Fields")
}
if splitAuthToken[0] != splitAuthToken[3] {
return fmt.Errorf("Auth Token Version Fields Don't match")
}
if !strings.HasPrefix(splitAuthToken[0], "gpgauth") {
return fmt.Errorf("Auth Token Version does not start with 'gpgauth'")
}
length, err := strconv.Atoi(splitAuthToken[1])
if err != nil {
return fmt.Errorf("Cannot Convert Auth Token Length Field to int: %w", err)
}
if len(splitAuthToken[2]) != length {
return fmt.Errorf("Auth Token Data Length does not Match Length Field")
}
return nil
}