<commit_before>package heartbleed_dtls

import (
	"bytes"
	_ "crypto/rand"
	_ "encoding/binary"
	"encoding/hex"
	"fmt"
	_ "time"
)

func (m *dtlsRecord) marshal() []byte {
	if m.raw != nil {
		return m.raw
	}

	m.length = uint16(len(m.dtlsBody))

	buf := make([]byte, 13+m.length)

	buf[0] = m.contentType
	buf[1] = uint8(m.version >> 8)
	buf[2] = uint8(m.version)
	buf[3] = uint8(m.epoch >> 8)
	buf[4] = uint8(m.epoch)
	buf[5] = uint8(m.sequenceNumber >> 40)
	buf[6] = uint8(m.sequenceNumber >> 32)
	buf[7] = uint8(m.sequenceNumber >> 24)
	buf[8] = uint8(m.sequenceNumber >> 16)
	buf[9] = uint8(m.sequenceNumber >> 8)
	buf[10] = uint8(m.sequenceNumber)
	buf[11] = uint8(m.length >> 8)
	buf[12] = uint8(m.length)

    copy(buf[13:], m.dtlsBody)

	m.raw = buf

	return buf
}

func (m *dtlsHandshake) Equal(i interface{}) bool {
	m1, ok := i.(dtlsHandshake)
	if !ok {
		return false
	}

	return bytes.Equal(m.raw, m1.raw) &&
		m.handshakeType == m.handshakeType &&
		m.length == m.length &&
		m.messageSequence == m.messageSequence &&
		m.fragmentOffset == m.fragmentOffset &&
		m.fragmentLength == m.fragmentLength &&
		bytes.Equal(m.body, m1.body)<commit_msg>Added unmarshal() and Equak() to dtlsRecord.<commit_after>package heartbleed_dtls

import (
	"bytes"
	_ "crypto/rand"
	_ "encoding/binary"
	"encoding/hex"
	"fmt"
	_ "time"
)

func (m *dtlsRecord) marshal() []byte {
	if m.raw != nil {
		return m.raw
	}

	m.length = uint16(len(m.dtlsBody))

	buf := make([]byte, 13+m.length)

	buf[0] = m.contentType
	buf[1] = uint8(m.version >> 8)
	buf[2] = uint8(m.version)
	buf[3] = uint8(m.epoch >> 8)
	buf[4] = uint8(m.epoch)
	buf[5] = uint8(m.sequenceNumber >> 40)
	buf[6] = uint8(m.sequenceNumber >> 32)
	buf[7] = uint8(m.sequenceNumber >> 24)
	buf[8] = uint8(m.sequenceNumber >> 16)
	buf[9] = uint8(m.sequenceNumber >> 8)
	buf[10] = uint8(m.sequenceNumber)
	buf[11] = uint8(m.length >> 8)
	buf[12] = uint8(m.length)

	copy(buf[13:], m.dtlsBody)

	m.raw = buf

	return buf
}

func (m *dtlsRecord) unmarshal(data []byte) bool {
	if len(data) < 13 {
		return false
	}
	m.raw = data
	m.contentType = uint8(data[0])
	m.version = uint16(data[1])<<8 | uint16(data[2])
	m.epoch = uint16(data[3])<<8 | uint16(data[4])
	m.sequenceNumber = uint64(data[5])<<40 | uint64(data[6])<<32 | uint64(data[7])<<24 | uint64(data[8])<<16 | uint64(data[9])<<8 | uint64(data[10])
	m.length = uint16(data[11])<<8 | uint16(data[12])

	copy(m.dtlsBody, data[12:])

	return true
}

func (m *dtlsRecord) Equal(i interface{}) bool {
	m1, ok := i.(dtlsRecord)
	if !ok {
		return false
	}

	return bytes.Equal(m.raw, m1.raw) &&
		m.contentType == m.contentType &&
		m.version == m.version &&
		m.epoch == m.epoch &&
		m.sequenceNumber == m.sequenceNumber &&
		m.length == m.length &&
		bytes.Equal(m.dtlsBody, m1.dtlsBody)
}

func (m *dtlsHandshake) Equal(i interface{}) bool {
	m1, ok := i.(dtlsHandshake)
	if !ok {
		return false
	}

	return bytes.Equal(m.raw, m1.raw) &&
		m.handshakeType == m.handshakeType &&
		m.length == m.length &&
		m.messageSequence == m.messageSequence &&
		m.fragmentOffset == m.fragmentOffset &&
		m.fragmentLength == m.fragmentLength &&
		bytes.Equal(m.body, m1.body)
{'fraction_non_alphanumeric': 0.1902654867256637, 'fraction_numerical': 0.04993678887484197, 'mean_word_length': 3.9530516431924885, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1602763', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1345, 'n_words': 251}