Deduplicate Random ID
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
Sarah Jamie Lewis 2021-11-23 14:45:25 -08:00
parent 6e2e67d26f
commit 781f4a919b
2 changed files with 3 additions and 12 deletions

View File

@ -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 {

View File

@ -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)