package handshake
import (
"github.com/pion/dtls/v2/internal/util"
)
type MessageCertificate struct {
Certificate [][]byte
}
func (m MessageCertificate ) Type () Type {
return TypeCertificate
}
const (
handshakeMessageCertificateLengthFieldSize = 3
)
func (m *MessageCertificate ) Marshal () ([]byte , error ) {
out := make ([]byte , handshakeMessageCertificateLengthFieldSize )
for _ , r := range m .Certificate {
out = append (out , make ([]byte , handshakeMessageCertificateLengthFieldSize )...)
util .PutBigEndianUint24 (out [len (out )-handshakeMessageCertificateLengthFieldSize :], uint32 (len (r )))
out = append (out , append ([]byte {}, r ...)...)
}
util .PutBigEndianUint24 (out [0 :], uint32 (len (out [handshakeMessageCertificateLengthFieldSize :])))
return out , nil
}
func (m *MessageCertificate ) Unmarshal (data []byte ) error {
if len (data ) < handshakeMessageCertificateLengthFieldSize {
return errBufferTooSmall
}
if certificateBodyLen := int (util .BigEndianUint24 (data )); certificateBodyLen +handshakeMessageCertificateLengthFieldSize != len (data ) {
return errLengthMismatch
}
offset := handshakeMessageCertificateLengthFieldSize
for offset < len (data ) {
certificateLen := int (util .BigEndianUint24 (data [offset :]))
offset += handshakeMessageCertificateLengthFieldSize
if offset +certificateLen > len (data ) {
return errLengthMismatch
}
m .Certificate = append (m .Certificate , append ([]byte {}, data [offset :offset +certificateLen ]...))
offset += certificateLen
}
return nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .