v1: pagination now deterministic
The standard JSON encoding has no guarantee of the order of keys, thus token values could differ, but still be equivalent.
This commit is contained in:
parent
dc431c22f3
commit
452c32d7d7
@ -15,8 +15,6 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
@ -297,19 +295,15 @@ func tokenToPageNumber(token, key string) (database.VulnerabilityNotificationPag
|
|||||||
}
|
}
|
||||||
|
|
||||||
page := database.VulnerabilityNotificationPageNumber{}
|
page := database.VulnerabilityNotificationPageNumber{}
|
||||||
err := json.NewDecoder(bytes.NewBuffer(msg)).Decode(&page)
|
_, err := fmt.Sscanf(string(msg), "old:%d|new:%d", &page.OldVulnerability, &page.NewVulnerability)
|
||||||
return page, err
|
return page, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func pageNumberToToken(page database.VulnerabilityNotificationPageNumber, key string) string {
|
func pageNumberToToken(page database.VulnerabilityNotificationPageNumber, key string) string {
|
||||||
var buf bytes.Buffer
|
unencryptedToken := []byte(fmt.Sprintf("old:%d|new:%d", page.OldVulnerability, page.NewVulnerability))
|
||||||
err := json.NewEncoder(&buf).Encode(page)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("failed to encode VulnerabilityNotificationPageNumber")
|
|
||||||
}
|
|
||||||
|
|
||||||
k, _ := fernet.DecodeKey(key)
|
k, _ := fernet.DecodeKey(key)
|
||||||
tokenBytes, err := fernet.EncryptAndSign(buf.Bytes(), k)
|
tokenBytes, err := fernet.EncryptAndSign(unencryptedToken, k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("failed to encrypt VulnerabilityNotificationpageNumber")
|
log.Fatal("failed to encrypt VulnerabilityNotificationpageNumber")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user