Skip to content

Commit

Permalink
Fix conversion issues in string session encoding and decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Mar 18, 2024
1 parent 1391ded commit 2127995
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions internal/session/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package session
import (
"encoding/base64"
"errors"
"strconv"
"strings"
)

Expand Down Expand Up @@ -62,8 +63,8 @@ func (s *StringSession) Encode() string {
string(s.authKey),
string(s.authKeyHash),
s.ipAddr,
string(rune(s.dcID)),
string(rune(s.appID)),
strconv.Itoa(s.dcID),
strconv.FormatInt(int64(s.appID), 10),
}
return stringPrefix + base64.RawURLEncoding.EncodeToString([]byte(strings.Join(sessionContents, "::")))
}
Expand All @@ -87,9 +88,19 @@ func (s *StringSession) Decode(encoded string) error {
case 2:
s.ipAddr = v
case 3:
s.dcID = int(v[0])
dcId, err := strconv.Atoi(v)
if err != nil {
return err
}

s.dcID = dcId
case 4:
s.appID = int32(v[0])
appId, err := strconv.ParseInt(v, 10, 32)
if err != nil {
return err
}

s.appID = int32(appId)
}
}
return nil
Expand Down

0 comments on commit 2127995

Please sign in to comment.