github.com/pion/dtls/v2@v2.2.12/pkg/protocol/handshake/message_client_key_exchange_test.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package handshake 5 6 import ( 7 "reflect" 8 "testing" 9 10 "github.com/pion/dtls/v2/internal/ciphersuite/types" 11 ) 12 13 func TestHandshakeMessageClientKeyExchange(t *testing.T) { 14 rawClientKeyExchange := []byte{ 15 0x20, 0x26, 0x78, 0x4a, 0x78, 0x70, 0xc1, 0xf9, 0x71, 0xea, 0x50, 0x4a, 0xb5, 0xbb, 0x00, 0x76, 16 0x02, 0x05, 0xda, 0xf7, 0xd0, 0x3f, 0xe3, 0xf7, 0x4e, 0x8a, 0x14, 0x6f, 0xb7, 0xe0, 0xc0, 0xff, 17 0x54, 18 } 19 parsedClientKeyExchange := &MessageClientKeyExchange{ 20 PublicKey: rawClientKeyExchange[1:], 21 KeyExchangeAlgorithm: types.KeyExchangeAlgorithmEcdhe, 22 } 23 24 c := &MessageClientKeyExchange{ 25 KeyExchangeAlgorithm: types.KeyExchangeAlgorithmEcdhe, 26 } 27 if err := c.Unmarshal(rawClientKeyExchange); err != nil { 28 t.Error(err) 29 } else if !reflect.DeepEqual(c, parsedClientKeyExchange) { 30 t.Errorf("handshakeMessageClientKeyExchange unmarshal: got %#v, want %#v", c, parsedClientKeyExchange) 31 } 32 33 raw, err := c.Marshal() 34 if err != nil { 35 t.Error(err) 36 } else if !reflect.DeepEqual(raw, rawClientKeyExchange) { 37 t.Errorf("handshakeMessageClientKeyExchange marshal: got %#v, want %#v", raw, rawClientKeyExchange) 38 } 39 }