From 2bf2b2d765c5003307544885b9321b32cc09d8bb Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 9 Nov 2020 00:34:48 +0100 Subject: entity: unique function to generate IDs --- identity/version.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'identity/version.go') diff --git a/identity/version.go b/identity/version.go index ae2474bf..ce5cc7d6 100644 --- a/identity/version.go +++ b/identity/version.go @@ -2,7 +2,6 @@ package identity import ( "crypto/rand" - "crypto/sha256" "encoding/json" "fmt" "strings" @@ -106,16 +105,11 @@ func (v *version) Id() entity.Id { if err != nil { panic(err) } - v.id = deriveId(data) + v.id = entity.DeriveId(data) } return v.id } -func deriveId(data []byte) entity.Id { - sum := sha256.Sum256(data) - return entity.Id(fmt.Sprintf("%x", sum)) -} - // Make a deep copy func (v *version) Clone() *version { // copy direct fields @@ -172,7 +166,7 @@ func (v *version) UnmarshalJSON(data []byte) error { return entity.NewErrNewFormatVersion(aux.FormatVersion) } - v.id = deriveId(data) + v.id = entity.DeriveId(data) v.times = aux.Times v.unixTime = aux.UnixTime v.name = aux.Name @@ -256,7 +250,7 @@ func (v *version) Write(repo repository.Repo) (repository.Hash, error) { } // make sure we set the Id when writing in the repo - v.id = deriveId(data) + v.id = entity.DeriveId(data) return hash, nil } -- cgit