github.com/pion/dtls/v2@v2.2.12/pkg/protocol/handshake/message_certificate_verify_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/pkg/crypto/hash"
    11  	"github.com/pion/dtls/v2/pkg/crypto/signature"
    12  )
    13  
    14  func TestHandshakeMessageCertificateVerify(t *testing.T) {
    15  	rawCertificateVerify := []byte{
    16  		0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x6b, 0x63, 0x17, 0xad, 0xbe, 0xb7, 0x7b, 0x0f,
    17  		0x86, 0x73, 0x39, 0x1e, 0xba, 0xb3, 0x50, 0x9c, 0xce, 0x9c, 0xe4, 0x8b, 0xe5, 0x13, 0x07, 0x59,
    18  		0x18, 0x1f, 0xe5, 0xa0, 0x2b, 0xca, 0xa6, 0xad, 0x02, 0x21, 0x00, 0xd3, 0xb5, 0x01, 0xbe, 0x87,
    19  		0x6c, 0x04, 0xa1, 0xdc, 0x28, 0xaa, 0x5f, 0xf7, 0x1e, 0x9c, 0xc0, 0x1e, 0x00, 0x2c, 0xe5, 0x94,
    20  		0xbb, 0x03, 0x0e, 0xf1, 0xcb, 0x28, 0x22, 0x33, 0x23, 0x88, 0xad,
    21  	}
    22  	parsedCertificateVerify := &MessageCertificateVerify{
    23  		HashAlgorithm:      hash.Algorithm(rawCertificateVerify[0]),
    24  		SignatureAlgorithm: signature.Algorithm(rawCertificateVerify[1]),
    25  		Signature:          rawCertificateVerify[4:],
    26  	}
    27  
    28  	c := &MessageCertificateVerify{}
    29  	if err := c.Unmarshal(rawCertificateVerify); err != nil {
    30  		t.Error(err)
    31  	} else if !reflect.DeepEqual(c, parsedCertificateVerify) {
    32  		t.Errorf("handshakeMessageCertificate unmarshal: got %#v, want %#v", c, parsedCertificateVerify)
    33  	}
    34  
    35  	raw, err := c.Marshal()
    36  	if err != nil {
    37  		t.Error(err)
    38  	} else if !reflect.DeepEqual(raw, rawCertificateVerify) {
    39  		t.Errorf("handshakeMessageCertificateVerify marshal: got %#v, want %#v", raw, rawCertificateVerify)
    40  	}
    41  }