Skip to content

Hash does not include type name #9

@bradleyjkemp

Description

@bradleyjkemp

Currently the hash only includes the fields of a struct and not the name of the struct type. This causes potentially unwanted hash collisions as seen below:

type TypeA struct {
        Foo string
        Bar string
}

type TypeB struct {
        Foo string
        Bar string
}

func TestTags(t *testing.T) {
        t1 := TypeA{"foo", "bar"}
        t2 := TypeB{"foo", "bar"}
        h1, err := Hash(t1, 1)
        if err != nil {
                panic(err)
        }
        h2, err := Hash(t2, 1)
        if err != nil {
                panic(err)
        }
        if h1 == h2 {
                t.Error("hash collision")
        }
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions