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

package extension

import (
	

	
)

const (
	supportedPointFormatsSize = 5
)

// SupportedPointFormats allows a Client/Server to negotiate
// the EllipticCurvePointFormats
//
// https://tools.ietf.org/html/rfc4492#section-5.1.2
type SupportedPointFormats struct {
	PointFormats []elliptic.CurvePointFormat
}

// TypeValue returns the extension TypeValue
func ( SupportedPointFormats) () TypeValue {
	return SupportedPointFormatsTypeValue
}

// Marshal encodes the extension
func ( *SupportedPointFormats) () ([]byte, error) {
	 := make([]byte, supportedPointFormatsSize)

	binary.BigEndian.PutUint16(, uint16(.TypeValue()))
	binary.BigEndian.PutUint16([2:], uint16(1+(len(.PointFormats))))
	[4] = byte(len(.PointFormats))

	for ,  := range .PointFormats {
		 = append(, byte())
	}
	return , nil
}

// Unmarshal populates the extension from encoded data
func ( *SupportedPointFormats) ( []byte) error {
	if len() <= supportedPointFormatsSize {
		return errBufferTooSmall
	} else if TypeValue(binary.BigEndian.Uint16()) != .TypeValue() {
		return errInvalidExtensionType
	}

	 := int(binary.BigEndian.Uint16([4:]))
	if supportedGroupsHeaderSize+() > len() {
		return errLengthMismatch
	}

	for  := 0;  < ; ++ {
		 := elliptic.CurvePointFormat([supportedPointFormatsSize+])
		switch  {
		case elliptic.CurvePointFormatUncompressed:
			.PointFormats = append(.PointFormats, )
		default:
		}
	}
	return nil
}