Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fix time.Time hashes #21

Merged
merged 1 commit into from
Nov 22, 2020
Merged

Fix time.Time hashes #21

merged 1 commit into from
Nov 22, 2020

Conversation

F21
Copy link
Contributor

@F21 F21 commented Feb 13, 2019

Fixes #16.

time.Time is a struct without any exported values. The current implementation treats it as a struct. Since it does not have any exported values, it's hashed as a struct with the name Time and nothing else. This means that any time.Time that is hashed will produce the same result, regardless of what its internal values are.

I added a check to check if the type being hashed is a time.Time, then use it to hash the binary version of the time (produced using the MarshalBinary() method). The MarshalBinary() method was used because it drops the monotonic clock component of the time before returning the binary representation, otherwise, 2 identical times with different monotonic clock components will generate different hashes.

@F21
Copy link
Contributor Author

F21 commented Feb 21, 2019

ping @mitchellh

@mibr020
Copy link

mibr020 commented Jun 17, 2019

@F21 Can I fork this and work on a fix since this PR is inactive

EDIT: ah you're waiting for @mitchellh to review this sorry i thought someone is waiting on the fix to be worked on

@F21
Copy link
Contributor Author

F21 commented Jun 17, 2019

@mibr020 I am just waiting for a review or a merge at the moment. Hopefully someone can get aroud to it soon.

@mitchellh
Copy link
Owner

This looks good. Thanks! Sorry this took literal years. Haha.

@mitchellh mitchellh merged commit ef219f8 into mitchellh:master Nov 22, 2020
@F21 F21 deleted the support-time.Time branch November 22, 2020 01:42
@adamhassel
Copy link
Contributor

Pretty sure this breaks hashing for time.Time values that has a string tag (or if the UseString option is on)...

@adamhassel adamhassel mentioned this pull request May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hashing time.Time does not generate unique hashes
4 participants