github.com/pion/dtls/v2@v2.2.12/handshake_test.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package dtls 5 6 import ( 7 "reflect" 8 "testing" 9 "time" 10 11 "github.com/pion/dtls/v2/pkg/protocol" 12 "github.com/pion/dtls/v2/pkg/protocol/extension" 13 "github.com/pion/dtls/v2/pkg/protocol/handshake" 14 ) 15 16 func TestHandshakeMessage(t *testing.T) { 17 rawHandshakeMessage := []byte{ 18 0x01, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0xfe, 0xfd, 0xb6, 19 0x2f, 0xce, 0x5c, 0x42, 0x54, 0xff, 0x86, 0xe1, 0x24, 0x41, 0x91, 0x42, 0x62, 0x15, 0xad, 20 0x16, 0xc9, 0x15, 0x8d, 0x95, 0x71, 0x8a, 0xbb, 0x22, 0xd7, 0x47, 0xec, 0xd8, 0x3d, 0xdc, 21 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 22 } 23 parsedHandshake := &handshake.Handshake{ 24 Header: handshake.Header{ 25 Length: 0x29, 26 FragmentLength: 0x29, 27 Type: handshake.TypeClientHello, 28 }, 29 Message: &handshake.MessageClientHello{ 30 Version: protocol.Version{Major: 0xFE, Minor: 0xFD}, 31 Random: handshake.Random{ 32 GMTUnixTime: time.Unix(3056586332, 0), 33 RandomBytes: [28]byte{0x42, 0x54, 0xff, 0x86, 0xe1, 0x24, 0x41, 0x91, 0x42, 0x62, 0x15, 0xad, 0x16, 0xc9, 0x15, 0x8d, 0x95, 0x71, 0x8a, 0xbb, 0x22, 0xd7, 0x47, 0xec, 0xd8, 0x3d, 0xdc, 0x4b}, 34 }, 35 SessionID: []byte{}, 36 Cookie: []byte{}, 37 CipherSuiteIDs: []uint16{}, 38 CompressionMethods: []*protocol.CompressionMethod{}, 39 Extensions: []extension.Extension{}, 40 }, 41 } 42 43 h := &handshake.Handshake{} 44 if err := h.Unmarshal(rawHandshakeMessage); err != nil { 45 t.Error(err) 46 } else if !reflect.DeepEqual(h, parsedHandshake) { 47 t.Errorf("handshakeMessageClientHello unmarshal: got %#v, want %#v", h, parsedHandshake) 48 } 49 50 raw, err := h.Marshal() 51 if err != nil { 52 t.Error(err) 53 } else if !reflect.DeepEqual(raw, rawHandshakeMessage) { 54 t.Errorf("handshakeMessageClientHello marshal: got %#v, want %#v", raw, rawHandshakeMessage) 55 } 56 }