2024-06-05 20:10:03 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-03-10 09:44:48 +00:00
|
|
|
package sctp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type param interface {
|
|
|
|
marshal() ([]byte, error)
|
|
|
|
length() int
|
|
|
|
}
|
|
|
|
|
2024-05-15 23:15:00 +00:00
|
|
|
// ErrParamTypeUnhandled is returned if unknown parameter type is specified.
|
|
|
|
var ErrParamTypeUnhandled = errors.New("unhandled ParamType")
|
2022-03-10 09:44:48 +00:00
|
|
|
|
|
|
|
func buildParam(t paramType, rawParam []byte) (param, error) {
|
|
|
|
switch t {
|
|
|
|
case forwardTSNSupp:
|
|
|
|
return (¶mForwardTSNSupported{}).unmarshal(rawParam)
|
|
|
|
case supportedExt:
|
|
|
|
return (¶mSupportedExtensions{}).unmarshal(rawParam)
|
|
|
|
case ecnCapable:
|
|
|
|
return (¶mECNCapable{}).unmarshal(rawParam)
|
|
|
|
case random:
|
|
|
|
return (¶mRandom{}).unmarshal(rawParam)
|
|
|
|
case reqHMACAlgo:
|
|
|
|
return (¶mRequestedHMACAlgorithm{}).unmarshal(rawParam)
|
|
|
|
case chunkList:
|
|
|
|
return (¶mChunkList{}).unmarshal(rawParam)
|
|
|
|
case stateCookie:
|
|
|
|
return (¶mStateCookie{}).unmarshal(rawParam)
|
|
|
|
case heartbeatInfo:
|
|
|
|
return (¶mHeartbeatInfo{}).unmarshal(rawParam)
|
|
|
|
case outSSNResetReq:
|
|
|
|
return (¶mOutgoingResetRequest{}).unmarshal(rawParam)
|
|
|
|
case reconfigResp:
|
|
|
|
return (¶mReconfigResponse{}).unmarshal(rawParam)
|
2024-06-05 20:10:03 +00:00
|
|
|
case zeroChecksumAcceptable:
|
|
|
|
return (¶mZeroChecksumAcceptable{}).unmarshal(rawParam)
|
2022-03-10 09:44:48 +00:00
|
|
|
default:
|
2024-05-15 23:15:00 +00:00
|
|
|
return nil, fmt.Errorf("%w: %v", ErrParamTypeUnhandled, t)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
}
|