Files
huso/rechner.go
2022-05-14 13:55:22 +02:00

46 lines
1.1 KiB
Go

package main
import (
"crypto/sha512"
"encoding/binary"
"fmt"
"strconv"
"strings"
"time"
)
func Sauce(malid int64, username string) string {
return fmt.Sprintf("%x", sha512.Sum512([]byte(registerSecret+strconv.FormatInt(malid, 10)+username)))
}
func BytesToInt64(bytes []byte) (int64, error) {
yes, c := binary.Varint(bytes)
if c <= 0 {
return yes, fmt.Errorf("int64 decode error: %s", bytes)
}
return yes, nil
}
func Int64ToByte(yes int64) []byte {
buf := make([]byte, binary.MaxVarintLen64)
n := binary.PutVarint(buf, yes)
return buf[:n]
}
func BytesToInt64AndDate(bytes []byte) (int64, time.Time, error) {
split := strings.Split(string(bytes), AppointSplit)
if len(split) != 2 {
return 0, time.Time{}, fmt.Errorf("invalid appointment split %s", string(bytes))
}
num, err := strconv.ParseInt(split[0], 10, 64)
if err != nil {
return num, time.Time{}, err
}
appoint, err := time.Parse(time.RFC3339, split[1])
return num, appoint, err
}
func Int64AndDateToBytes(num int64, appoint time.Time) []byte {
return []byte(fmt.Sprintf("%d%s%s", num, AppointSplit, appoint.Format(time.RFC3339)))
}