This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
2018-02-20 17:20:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-02-21 00:51:06 +00:00
|
|
|
"crypto/sha512"
|
2018-02-20 17:20:07 +00:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2021-02-13 17:34:44 +00:00
|
|
|
func GenerateToken(pkey []byte, id int, a ...[]byte) ([]byte, error) {
|
2018-02-21 00:51:06 +00:00
|
|
|
h := sha512.New()
|
2018-02-20 17:20:07 +00:00
|
|
|
|
2018-02-23 19:37:08 +00:00
|
|
|
h.Write([]byte(fmt.Sprintf("%x", pkey)))
|
2021-02-18 00:14:32 +00:00
|
|
|
// Challenge toctoc(6) should not have that
|
|
|
|
if id != 0 && id != 6 {
|
2018-02-23 19:37:08 +00:00
|
|
|
h.Write([]byte(fmt.Sprintf(":%d", id)))
|
|
|
|
}
|
2018-02-20 17:20:07 +00:00
|
|
|
|
|
|
|
for _, v := range a {
|
|
|
|
h.Write([]byte(":"))
|
|
|
|
h.Write(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return h.Sum(nil), nil
|
|
|
|
}
|