Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handshake_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (h *handshakeCache) push(data []byte, epoch, messageSequence uint16, typ ha
defer h.mu.Unlock()

h.cache = append(h.cache, &handshakeCacheItem{
data: append([]byte{}, data...),
data: data,
epoch: epoch,
messageSequence: messageSequence,
typ: typ,
Expand Down
26 changes: 17 additions & 9 deletions pkg/protocol/handshake/message_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,30 @@ const (

// Marshal encodes the Handshake.
func (m *MessageCertificate) Marshal() ([]byte, error) {
out := make([]byte, handshakeMessageCertificateLengthFieldSize)
total := handshakeMessageCertificateLengthFieldSize

for _, r := range m.Certificate {
for _, cert := range m.Certificate {
total += handshakeMessageCertificateLengthFieldSize + len(cert)
}

out := make([]byte, total)

// Total Payload Size
//nolint:gosec // G115
util.PutBigEndianUint24(out, uint32(total-handshakeMessageCertificateLengthFieldSize))
offset := handshakeMessageCertificateLengthFieldSize

for _, cert := range m.Certificate {
// Certificate Length
//nolint:makezero // todo: fix
out = append(out, make([]byte, handshakeMessageCertificateLengthFieldSize)...)
//nolint:gosec // G115
util.PutBigEndianUint24(out[len(out)-handshakeMessageCertificateLengthFieldSize:], uint32(len(r)))
util.PutBigEndianUint24(out[offset:], uint32(len(cert)))
offset += handshakeMessageCertificateLengthFieldSize

// Certificate body
out = append(out, append([]byte{}, r...)...) //nolint:makezero // todo: fix
copy(out[offset:], cert)
offset += len(cert)
}

// Total Payload Size
util.PutBigEndianUint24(out[0:], uint32(len(out[handshakeMessageCertificateLengthFieldSize:]))) //nolint:gosec //G115

return out, nil
}

Expand Down
Loading