From 781f4a919b52ebd71f92abf86fc3b5213f2f709b Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 23 Nov 2021 14:45:25 -0800 Subject: [PATCH] Deduplicate Random ID --- app/app.go | 12 ++---------- model/profile.go | 3 +-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/app.go b/app/app.go index 6b78f0e..7c487fc 100644 --- a/app/app.go +++ b/app/app.go @@ -1,15 +1,14 @@ package app import ( - "crypto/rand" "cwtch.im/cwtch/app/plugins" "cwtch.im/cwtch/event" + "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/model/constants" "cwtch.im/cwtch/peer" "cwtch.im/cwtch/protocol/connections" "cwtch.im/cwtch/storage" - "encoding/hex" "fmt" "git.openprivacy.ca/openprivacy/connectivity" "git.openprivacy.ca/openprivacy/log" @@ -85,18 +84,11 @@ func (ac *applicationCore) DeletePeer(onion string) { delete(ac.eventBuses, onion) } -// GenerateRandomID generates a random 16 byte hex id code -func GenerateRandomID() string { - randBytes := make([]byte, 16) - rand.Read(randBytes) - return path.Join(hex.EncodeToString(randBytes)) -} - func (app *application) CreateTaggedPeer(name string, password string, tag string) { app.appmutex.Lock() defer app.appmutex.Unlock() - profileDirectory := path.Join(app.directory, "profiles", GenerateRandomID()) + profileDirectory := path.Join(app.directory, "profiles", model.GenerateRandomID()) profile, err := peer.CreateEncryptedStorePeer(profileDirectory, name, password) if err != nil { diff --git a/model/profile.go b/model/profile.go index c18239f..acf06e4 100644 --- a/model/profile.go +++ b/model/profile.go @@ -6,7 +6,6 @@ import ( "encoding/json" "golang.org/x/crypto/ed25519" "io" - "path/filepath" "sync" ) @@ -67,7 +66,7 @@ func getRandomness(arr *[]byte) { func GenerateRandomID() string { randBytes := make([]byte, 16) rand.Read(randBytes) - return filepath.Join(hex.EncodeToString(randBytes)) + return hex.EncodeToString(randBytes) } // GetCopy returns a full deep copy of the Profile struct and its members (timeline inclusion control by arg)