mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 19:24:02 +03:00
FILE / ScuroNeko/mtg
mtglib/internal/tls/init_test.go
Исходный файл и его история в репозитории.
31 lines
605 B
Go
31 lines
605 B
Go
package tls
|
|
|
|
import (
|
|
"encoding/binary"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
type WriterMock struct {
|
|
mock.Mock
|
|
}
|
|
|
|
func (m *WriterMock) Write(p []byte) (int, error) {
|
|
args := m.Called(p)
|
|
return args.Int(0), args.Error(1)
|
|
}
|
|
|
|
// makeTLSRecord builds a raw TLS record from hardcoded offsets:
|
|
// type(1) + version(2, {3,3}) + length(2, big-endian) + payload.
|
|
func MakeTLSRecord(recordType byte, payload []byte) []byte {
|
|
buf := make([]byte, 5+len(payload))
|
|
|
|
buf[0] = recordType
|
|
buf[1] = 3
|
|
buf[2] = 3
|
|
binary.BigEndian.PutUint16(buf[3:5], uint16(len(payload)))
|
|
copy(buf[5:], payload)
|
|
|
|
return buf
|
|
}
|