Verified Commit 66c7c534 authored by onyinyang's avatar onyinyang 🔒
Browse files

Store bucket key as byte array rather than hash

parent b1293520
Loading
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ type RootKey hash.Hash

// BucketKey is the hmac key derived from RootKey for a specific distributor
type BucketKey struct {
	bucketKey hash.Hash
	bucketKey []byte
}

func NewRootKey(secretKey string) RootKey {
@@ -62,16 +62,16 @@ func NewRootKey(secretKey string) RootKey {
func NewBucketKey(secret string, distName string) BucketKey {
	rootKey := NewRootKey(secret)
	rootKey.Write([]byte(distName))
	bucketKey := rootKey.Sum(nil)
	return BucketKey{
		bucketKey: hmac.New(sha256.New, bucketKey),
		bucketKey: rootKey.Sum(nil),
	}
}

func (b *BucketKey) NewBucketHash(usrBytes []byte) Hashkey {
	b.bucketKey.Reset()
	b.bucketKey.Write(usrBytes)
	h := b.bucketKey.Sum(nil)
	bucketHash := hmac.New(sha256.New, b.bucketKey)
	bucketHash.Reset()
	bucketHash.Write(usrBytes)
	h := bucketHash.Sum(nil)
	return Hashkey(binary.BigEndian.Uint64(h[:8]))
}