-
Notifications
You must be signed in to change notification settings - Fork 0
/
favs.go
55 lines (46 loc) · 1.27 KB
/
favs.go
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
package types
import (
"crypto/sha1"
"encoding/hex"
"strconv"
)
type FavList struct {
ID int `json:"id"`
Name string `json:"name"`
IsPublic bool `json:"public"`
DoNotify bool `json:"notify"`
DoAutoRead bool `json:"auto_read"`
IncludesP2P bool `json:"include_p2p"`
Description string `json:"description"`
PasswordHash string `json:"passwort_hash"`
EntryCount int `json:"entry_count"`
UnreadReleases int `json:"unread_releases"`
}
/*
TestPassword tests if a password for a list is correct.
https://www.xrel.to/wiki/1754/api-favs-lists.html
*/
func (f *FavList) TestPassword(password string) bool {
if f.PasswordHash == "" {
return true
}
h := sha1.New()
h.Write([]byte(strconv.Itoa(f.ID) + "\n\r" + password))
passwordHashString := hex.EncodeToString(h.Sum(nil))
for i := 0; i < h.Size(); i++ {
if passwordHashString[i] != f.PasswordHash[i] {
return false
}
}
return true
}
type ShortFavList struct {
ID int `json:"id"`
Name string `json:"string"`
EntryCount int `json:"entry_count"`
UnreadReleases int `json:"unread_releases"`
}
type FavListEntryModificationResult struct {
FavList ShortFavList `json:"fav_list"`
ExtInfo ShortExtInfo `json:"ext_info"`
}