diff --git a/libgm/client.go b/libgm/client.go index 22944c0..35fdd10 100644 --- a/libgm/client.go +++ b/libgm/client.go @@ -293,7 +293,7 @@ func (c *Client) updateJWK(jwk *crypto.JWK) { } func (c *Client) updateTachyonAuthToken(t []byte) { - authenticatedAt := util.TimestampNow() + authenticatedAt := time.Now().UTC() c.authData.TachyonAuthToken = t c.authData.AuthenticatedAt = &authenticatedAt c.Logger.Debug().Any("authenticatedAt", authenticatedAt).Any("tachyonAuthToken", t).Msg("Updated TachyonAuthToken") diff --git a/libgm/image_builder.go b/libgm/image_builder.go index 82dcc56..bfb3363 100644 --- a/libgm/image_builder.go +++ b/libgm/image_builder.go @@ -130,7 +130,7 @@ func (mb *MessageBuilder) AddImage(imgBytes []byte, mime string) *MessageBuilder func (mb *MessageBuilder) newImageData(imgBytes []byte, mime string) (*Image, error) { // TODO explode on unsupported types imgType := ImageTypes[mime] - imageId := util.GenerateImageId() + imageId := util.GenerateImageID() imageName := util.RandStr(8) + "." + imgType.Extension decryptionKey, err := crypto.GenerateKey(32) if err != nil { diff --git a/libgm/message_builder.go b/libgm/message_builder.go index 012d94d..fceede6 100644 --- a/libgm/message_builder.go +++ b/libgm/message_builder.go @@ -95,7 +95,7 @@ func (mb *MessageBuilder) Build() (*binary.SendMessagePayload, error) { } if mb.tmpID == "" { - mb.tmpID = util.GenerateTmpId() + mb.tmpID = util.GenerateTmpID() } return mb.newSendConversationMessage(), nil @@ -106,7 +106,7 @@ func (c *Client) NewMessageBuilder() *MessageBuilder { client: c, } - tmpId := util.GenerateTmpId() + tmpId := util.GenerateTmpID() mb.SetTmpID(tmpId) return mb diff --git a/libgm/util/func.go b/libgm/util/func.go index b15f52b..844afae 100644 --- a/libgm/util/func.go +++ b/libgm/util/func.go @@ -1,8 +1,6 @@ package util import ( - crand "crypto/rand" - "encoding/hex" "encoding/json" "fmt" "math/rand" @@ -17,10 +15,6 @@ import ( var Charset = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") -func TimestampNow() time.Time { - return time.Now().UTC() -} - func RandStr(length int) string { b := make([]rune, length) for i := range b { @@ -29,45 +23,23 @@ func RandStr(length int) string { return string(b) } -func GenerateImageId() string { +func GenerateImageID() string { part1 := RandomUUIDv4() part2 := RandStr(25) return part1 + "/" + part2 } -func GenerateTmpId() string { +func GenerateTmpID() string { src := rand.NewSource(time.Now().UnixNano()) r := rand.New(src) randNum := r.Int63n(1e12) return fmt.Sprintf("tmp_%012d", randNum) } -func ParseTimestamp(unixTs int64) time.Time { - seconds := unixTs / int64(time.Second/time.Microsecond) - nanoseconds := (unixTs % int64(time.Second/time.Microsecond)) * int64(time.Microsecond/time.Nanosecond) - return time.Unix(seconds, nanoseconds).UTC() -} - -func RandomHex(n int) string { - bytes := make([]byte, n) - crand.Read(bytes) - return hex.EncodeToString(bytes) -} - func RandomUUIDv4() string { return uuid.New().String() } -func RemoveFromSlice(s []string, v string) []string { - newS := []string{} - for _, i := range s { - if i != v { - newS = append(newS, i) - } - } - return newS -} - func BuildRelayHeaders(req *http.Request, contentType string, accept string) { req.Header.Add("host", "instantmessaging-pa.googleapis.com") req.Header.Add("connection", "keep-alive") diff --git a/portal.go b/portal.go index fd12992..b3c95b0 100644 --- a/portal.go +++ b/portal.go @@ -1220,7 +1220,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing } } - txnID := util.GenerateTmpId() + txnID := util.GenerateTmpID() portal.outgoingMessagesLock.Lock() portal.outgoingMessages[txnID] = &outgoingMessage{Event: evt} portal.outgoingMessagesLock.Unlock()