(data *session.Data, appID int32)
| 16 | ) |
| 17 | |
| 18 | func EncodeToPyrogramSession(data *session.Data, appID int32) (string, error) { |
| 19 | buf := new(bytes.Buffer) |
| 20 | if err := buf.WriteByte(byte(data.DC)); err != nil { |
| 21 | return "", err |
| 22 | } |
| 23 | if err := binary.Write(buf, binary.BigEndian, appID); err != nil { |
| 24 | return "", err |
| 25 | } |
| 26 | var testMode byte |
| 27 | if data.Config.TestMode { |
| 28 | testMode = 1 |
| 29 | } |
| 30 | if err := buf.WriteByte(testMode); err != nil { |
| 31 | return "", err |
| 32 | } |
| 33 | if len(data.AuthKey) != 256 { |
| 34 | return "", errors.New("auth key must be 256 bytes long") |
| 35 | } |
| 36 | if _, err := buf.Write(data.AuthKey); err != nil { |
| 37 | return "", err |
| 38 | } |
| 39 | if len(data.AuthKeyID) != 8 { |
| 40 | return "", errors.New("auth key ID must be 8 bytes long") |
| 41 | } |
| 42 | if _, err := buf.Write(data.AuthKeyID); err != nil { |
| 43 | return "", err |
| 44 | } |
| 45 | if err := buf.WriteByte(0); err != nil { |
| 46 | return "", err |
| 47 | } |
| 48 | // Convert the bytes buffer to a base64 string |
| 49 | encodedString := base64.URLEncoding.EncodeToString(buf.Bytes()) |
| 50 | trimmedEncoded := strings.TrimRight(encodedString, "=") |
| 51 | return trimmedEncoded, nil |
| 52 | } |
no test coverage detected