Revert "v1: pagination now deterministic"

This reverts commit 24f329fea674e04c76f5e87c22eea1800e6bc413.

This was unnecessary.
This commit is contained in:
Jimmy Zelinskie 2016-02-24 16:21:47 -05:00
parent 3563cf9061
commit 1557a27a8c

View File

@ -15,6 +15,8 @@
package v1 package v1
import ( import (
"bytes"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"time" "time"
@ -295,15 +297,19 @@ func tokenToPageNumber(token, key string) (database.VulnerabilityNotificationPag
} }
page := database.VulnerabilityNotificationPageNumber{} page := database.VulnerabilityNotificationPageNumber{}
_, err := fmt.Sscanf(string(msg), "old:%d|new:%d", &page.OldVulnerability, &page.NewVulnerability) err := json.NewDecoder(bytes.NewBuffer(msg)).Decode(&page)
return page, err return page, err
} }
func pageNumberToToken(page database.VulnerabilityNotificationPageNumber, key string) string { func pageNumberToToken(page database.VulnerabilityNotificationPageNumber, key string) string {
unencryptedToken := []byte(fmt.Sprintf("old:%d|new:%d", page.OldVulnerability, page.NewVulnerability)) var buf bytes.Buffer
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(unencryptedToken, k) tokenBytes, err := fernet.EncryptAndSign(buf.Bytes(), k)
if err != nil { if err != nil {
log.Fatal("failed to encrypt VulnerabilityNotificationpageNumber") log.Fatal("failed to encrypt VulnerabilityNotificationpageNumber")
} }