package sessionimport ()// https://github.com/LonamiWebs/Telethon/blob/master/telethon/sessions/string.py#L11constlatestTelethonVersionbyte = '1'// TelethonSession decodes Telethon's StringSession string to the Data.// Notice that Telethon does not save tg.Config and server salt.//// See https://docs.telethon.dev/en/latest/modules/sessions.html#telethon.sessions.string.StringSession.//// See https://github.com/LonamiWebs/Telethon/blob/master/telethon/sessions/string.py#L29-L46.func ( string) (*Data, error) {iflen() < 1 {returnnil, errors.Errorf("given string too small: %d", len()) } := [0]if != latestTelethonVersion {returnnil, errors.Errorf("unexpected version %q, latest supported is %q", ,latestTelethonVersion, ) } , := base64.URLEncoding.DecodeString([1:])if != nil {returnnil, errors.Wrap(, "decode hex") }returndecodeStringSession()}func ( []byte) (*Data, error) {// Given parameter should contain version + data // where data encoded using pack as '>B4sH256s' or '>B16sH256s' // depending on IP type. // // Table: // // | Size | Type | Description | // |------|--------|-------------| // | 1 | byte | DC ID | // | 4/16 | bytes | IP address | // | 2 | uint16 | Port | // | 256 | bytes | Auth key |varintswitchlen() {case263: = 4case275: = 16default:returnnil, errors.Errorf("decoded hex has invalid length: %d", len()) }// | 1 | byte | DC ID | := [0]// | 4/16 | bytes | IP address | := make(net.IP, 0, 16) = append(, [1:1+]...)// | 2 | uint16 | Port | := binary.BigEndian.Uint16([1+ : 3+])// | 256 | bytes | Auth key |varcrypto.Keycopy([:], [3+:]) := .WithID().IDreturn &Data{DC: int(),Addr: net.JoinHostPort(.String(), strconv.Itoa(int())),AuthKey: [:],AuthKeyID: [:], }, nil}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.