2016-08-07 03:08:30 -04:00
|
|
|
package srtp_test
|
|
|
|
|
|
|
|
import (
|
2017-12-16 17:31:05 -05:00
|
|
|
"context"
|
2016-08-07 03:08:30 -04:00
|
|
|
"testing"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
|
|
|
. "github.com/v2fly/v2ray-core/v5/transport/internet/headers/srtp"
|
2016-08-07 03:08:30 -04:00
|
|
|
)
|
|
|
|
|
2016-12-08 10:27:41 -05:00
|
|
|
func TestSRTPWrite(t *testing.T) {
|
2016-08-07 03:08:30 -04:00
|
|
|
content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
|
2017-12-16 17:31:05 -05:00
|
|
|
srtpRaw, err := New(context.Background(), &Config{})
|
2019-01-18 09:59:39 -05:00
|
|
|
common.Must(err)
|
2017-12-16 17:31:05 -05:00
|
|
|
|
|
|
|
srtp := srtpRaw.(*SRTP)
|
2016-12-08 10:27:41 -05:00
|
|
|
|
2018-03-11 18:45:24 -04:00
|
|
|
payload := buf.New()
|
2018-11-02 16:34:04 -04:00
|
|
|
srtp.Serialize(payload.Extend(srtp.Size()))
|
2018-04-19 16:56:55 -04:00
|
|
|
payload.Write(content)
|
2016-12-06 05:03:42 -05:00
|
|
|
|
2019-01-18 09:59:39 -05:00
|
|
|
expectedLen := int32(len(content)) + srtp.Size()
|
|
|
|
if payload.Len() != expectedLen {
|
|
|
|
t.Error("expected ", expectedLen, " of bytes, but got ", payload.Len())
|
|
|
|
}
|
2016-08-07 03:08:30 -04:00
|
|
|
}
|