peterldowns/pgtestdb

database instance names contain redundant data

Closed this issue · 1 comments

Database instance names all look like the following:

3aa05350d41d8cd98f00b204e9800998ecf8427e
f1c841c1d41d8cd98f00b204e9800998ecf8427e
e5dde3f7d41d8cd98f00b204e9800998ecf8427e

Note that only the first eight characters change. The remaining are all identical: d41d8cd98f00b204e9800998ecf8427e

This is because the bytes are generated with this function:

func randomID(prefix string) (string, error) {

The function doesn't do what it's meant to. hash.Sum(bytes) is not generating a hash of the 4 random bytes, but rather generating a constant hash of empty data and appending it to the four random bytes.

Besides this bug in the code, though, the general idea of taking a hash of the 4 random bytes is odd. It adds no entropy and only serves to make the id longer and unwieldy.

I'd suggest replacing this with a call to stdlib uuid.

The function doesn't do what it's meant to. hash.Sum(bytes) is not generating a hash of the 4 random bytes, but rather generating a constant hash of empty data and appending it to the four random bytes.

Good catch! You're right.

Besides this bug in the code, though, the general idea of taking a hash of the 4 random bytes is odd. It adds no entropy and only serves to make the id longer and unwieldy.

Wish I could remember what I was thinking — I agree with you.

I'd suggest replacing this with a call to stdlib uuid.

I'm going to fix it by just hexifying the bytes and removing the hashing part, makes for a nice short string with the same amount of entropy. PR coming shortly.