frontend: increase hash length to 11 bytes
In changing the hash function and salt in https://golang.org/cl/84977
there is a (very small) chance that collisions may occur with newly
created snippets. If Bob created a snippet using the previous hash,
but Alice created a new snippet using the new method that happened to
have the same 10-byte string ID, then it would overwrite Bob’s snippet.
Increase the length by 1 to avoid this and to also clearly delineate
which are saved using the old method and which are using the new one.
Change-Id: Ide36b76becb3b105899d71d7965291ec51961278
Reviewed-on: https://go-review.googlesource.com/85035
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/frontend/server_test.go b/frontend/server_test.go
index 7c62c66..220ff03 100644
--- a/frontend/server_test.go
+++ b/frontend/server_test.go
@@ -102,7 +102,7 @@
}{
{"OPTIONS no-op", http.MethodOptions, http.StatusOK, nil, nil},
{"Non-POST request", http.MethodGet, http.StatusMethodNotAllowed, nil, nil},
- {"Standard flow", http.MethodPost, http.StatusOK, []byte("Snippy McSnipface"), []byte("wX8wRZRjvv")},
+ {"Standard flow", http.MethodPost, http.StatusOK, []byte("Snippy McSnipface"), []byte("N_M_YelfGeR")},
{"Snippet too large", http.MethodPost, http.StatusRequestEntityTooLarge, make([]byte, maxSnippetSize+1), nil},
}
diff --git a/frontend/share.go b/frontend/share.go
index 4e9de47..1635a7d 100644
--- a/frontend/share.go
+++ b/frontend/share.go
@@ -33,7 +33,7 @@
sum := h.Sum(nil)
b := make([]byte, base64.URLEncoding.EncodedLen(len(sum)))
base64.URLEncoding.Encode(b, sum)
- return string(b)[:10]
+ return string(b)[:11]
}
func (s *server) handleShare(w http.ResponseWriter, r *http.Request) {