Hunter0x7c7
2022-08-11 a82f9cb69f63aaeba40c024960deda7d75b9fece
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package aead
 
import (
    "fmt"
    "strconv"
    "testing"
    "time"
 
    "github.com/stretchr/testify/assert"
)
 
func TestCreateAuthID(t *testing.T) {
    key := KDF16([]byte("Demo Key for Auth ID Test"), "Demo Path for Auth ID Test")
    authid := CreateAuthID(key, time.Now().Unix())
 
    fmt.Println(key)
    fmt.Println(authid)
}
 
func TestCreateAuthIDAndDecode(t *testing.T) {
    key := KDF16([]byte("Demo Key for Auth ID Test"), "Demo Path for Auth ID Test")
    authid := CreateAuthID(key, time.Now().Unix())
 
    fmt.Println(key)
    fmt.Println(authid)
 
    AuthDecoder := NewAuthIDDecoderHolder()
    var keyw [16]byte
    copy(keyw[:], key)
    AuthDecoder.AddUser(keyw, "Demo User")
    res, err := AuthDecoder.Match(authid)
    fmt.Println(res)
    fmt.Println(err)
    assert.Equal(t, "Demo User", res)
    assert.Nil(t, err)
}
 
func TestCreateAuthIDAndDecode2(t *testing.T) {
    key := KDF16([]byte("Demo Key for Auth ID Test"), "Demo Path for Auth ID Test")
    authid := CreateAuthID(key, time.Now().Unix())
 
    fmt.Println(key)
    fmt.Println(authid)
 
    AuthDecoder := NewAuthIDDecoderHolder()
    var keyw [16]byte
    copy(keyw[:], key)
    AuthDecoder.AddUser(keyw, "Demo User")
    res, err := AuthDecoder.Match(authid)
    fmt.Println(res)
    fmt.Println(err)
    assert.Equal(t, "Demo User", res)
    assert.Nil(t, err)
 
    key2 := KDF16([]byte("Demo Key for Auth ID Test2"), "Demo Path for Auth ID Test")
    authid2 := CreateAuthID(key2, time.Now().Unix())
 
    res2, err2 := AuthDecoder.Match(authid2)
    assert.EqualError(t, err2, "user do not exist")
    assert.Nil(t, res2)
}
 
func TestCreateAuthIDAndDecodeMassive(t *testing.T) {
    key := KDF16([]byte("Demo Key for Auth ID Test"), "Demo Path for Auth ID Test")
    authid := CreateAuthID(key, time.Now().Unix())
 
    fmt.Println(key)
    fmt.Println(authid)
 
    AuthDecoder := NewAuthIDDecoderHolder()
    var keyw [16]byte
    copy(keyw[:], key)
    AuthDecoder.AddUser(keyw, "Demo User")
    res, err := AuthDecoder.Match(authid)
    fmt.Println(res)
    fmt.Println(err)
    assert.Equal(t, "Demo User", res)
    assert.Nil(t, err)
 
    for i := 0; i <= 10000; i++ {
        key2 := KDF16([]byte("Demo Key for Auth ID Test2"), "Demo Path for Auth ID Test", strconv.Itoa(i))
        var keyw2 [16]byte
        copy(keyw2[:], key2)
        AuthDecoder.AddUser(keyw2, "Demo User"+strconv.Itoa(i))
    }
 
    authid3 := CreateAuthID(key, time.Now().Unix())
 
    res2, err2 := AuthDecoder.Match(authid3)
    assert.Equal(t, "Demo User", res2)
    assert.Nil(t, err2)
}
 
func TestCreateAuthIDAndDecodeSuperMassive(t *testing.T) {
    key := KDF16([]byte("Demo Key for Auth ID Test"), "Demo Path for Auth ID Test")
    authid := CreateAuthID(key, time.Now().Unix())
 
    fmt.Println(key)
    fmt.Println(authid)
 
    AuthDecoder := NewAuthIDDecoderHolder()
    var keyw [16]byte
    copy(keyw[:], key)
    AuthDecoder.AddUser(keyw, "Demo User")
    res, err := AuthDecoder.Match(authid)
    fmt.Println(res)
    fmt.Println(err)
    assert.Equal(t, "Demo User", res)
    assert.Nil(t, err)
 
    for i := 0; i <= 1000000; i++ {
        key2 := KDF16([]byte("Demo Key for Auth ID Test2"), "Demo Path for Auth ID Test", strconv.Itoa(i))
        var keyw2 [16]byte
        copy(keyw2[:], key2)
        AuthDecoder.AddUser(keyw2, "Demo User"+strconv.Itoa(i))
    }
 
    authid3 := CreateAuthID(key, time.Now().Unix())
 
    before := time.Now()
    res2, err2 := AuthDecoder.Match(authid3)
    after := time.Now()
    assert.Equal(t, "Demo User", res2)
    assert.Nil(t, err2)
 
    fmt.Println(after.Sub(before).Seconds())
}