package tgquick import ( "encoding/binary" "testing" ) func TestPopRI_RoundTrip(t *testing.T) { payload := []byte{1, 2, 3, 4, 5, 6, 7, 8} enc, err := randomizedIntermediateEncode(payload) if err != nil { t.Fatal(err) } var acc []byte acc = append(acc, enc...) got, ok := popRI(&acc) if !ok || len(acc) != 0 { t.Fatalf("popRI: ok=%v rest=%d", ok, len(acc)) } if string(got) != string(payload) { t.Fatalf("payload mismatch: %v vs %v", got, payload) } } func TestIsResPQ(t *testing.T) { nonce := make([]byte, 16) // resPQ: constructor + nonce(16) + server_nonce(16) + pq bytes + Vector msgData := make([]byte, 4+16+16+4+4) binary.LittleEndian.PutUint32(msgData, tlResPQ) copy(msgData[4:20], nonce) copy(msgData[20:36], nonce) // pq empty, fingerprints empty if !isResPQ(wrapUnencrypted(msgData)) { t.Fatal("expected resPQ") } } func TestIsUnencryptedDCEnvelope(t *testing.T) { msgData := make([]byte, 8) binary.LittleEndian.PutUint32(msgData, 0x11223344) w := wrapUnencrypted(msgData) if !isUnencryptedDCEnvelope(w) { t.Fatal("expected envelope for arbitrary constructor") } if isResPQ(w) { t.Fatal("not resPQ") } }