first working version

This commit is contained in:
ston1th 2018-09-14 00:14:49 +02:00
commit 85f93bae69
32 changed files with 863 additions and 571 deletions

View file

@ -12,7 +12,7 @@ const keySize = jwt.KeySize / 2
func genKey(length int) (bytes []byte) {
bytes = make([]byte, length)
if _, err := io.ReadFull(rand.Reader, bytes); err != nil {
if _, err := rand.Reader.Read(bytes); err != nil {
log.Println("genKey:", err)
}
return
@ -31,13 +31,14 @@ func checkXsrf(xsrf string, secret []byte) bool {
return subtle.ConstantTimeCompare(secret, xor(t[keySize:], t[:keySize])) == 1
}
func xor(a, b []byte) []byte {
func xor(a, b []byte) (c []byte) {
n := len(a)
if len(b) != n {
if len(b) < n {
return nil
}
c = make([]byte, n)
for i := 0; i < n; i++ {
a[i] = a[i] ^ b[i]
c[i] = a[i] ^ b[i]
}
return a
return
}