// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package recordlayer

import (
	
	
)

// InnerPlaintext implements DTLSInnerPlaintext
//
// https://datatracker.ietf.org/doc/html/rfc9146#name-record-layer-extensions
type InnerPlaintext struct {
	Content  []byte
	RealType protocol.ContentType
	Zeros    uint
}

// Marshal encodes a DTLS InnerPlaintext to binary.
func ( *InnerPlaintext) () ([]byte, error) {
	var  cryptobyte.Builder
	.AddBytes(.Content)
	.AddUint8(uint8(.RealType))
	.AddBytes(make([]byte, .Zeros))

	return .Bytes()
}

// Unmarshal populates a DTLS InnerPlaintext from binary.
func ( *InnerPlaintext) ( []byte) error {
	// Process in reverse
	 := len() - 1
	for  >= 0 {
		if [] != 0 {
			.Zeros = uint(len() - 1 - ) //nolint:gosec // G115

			break
		}
		--
	}
	if  == 0 {
		return errBufferTooSmall
	}
	.RealType = protocol.ContentType([])
	.Content = append([]byte{}, [:]...)

	return nil
}