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"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
CookieEcho represents an SCTP Chunk of type CookieEcho
|
|
|
|
|
2024-05-15 23:15:00 +00:00
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Type = 10 |Chunk Flags | Length |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Cookie |
|
|
|
|
| |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2022-03-10 09:44:48 +00:00
|
|
|
*/
|
|
|
|
type chunkCookieEcho struct {
|
|
|
|
chunkHeader
|
|
|
|
cookie []byte
|
|
|
|
}
|
|
|
|
|
2024-05-15 23:15:00 +00:00
|
|
|
// Cookie echo chunk errors
|
|
|
|
var (
|
|
|
|
ErrChunkTypeNotCookieEcho = errors.New("ChunkType is not of type COOKIEECHO")
|
|
|
|
)
|
2022-03-10 09:44:48 +00:00
|
|
|
|
|
|
|
func (c *chunkCookieEcho) unmarshal(raw []byte) error {
|
|
|
|
if err := c.chunkHeader.unmarshal(raw); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.typ != ctCookieEcho {
|
2024-05-15 23:15:00 +00:00
|
|
|
return fmt.Errorf("%w: actually is %s", ErrChunkTypeNotCookieEcho, c.typ.String())
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
c.cookie = c.raw
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *chunkCookieEcho) marshal() ([]byte, error) {
|
|
|
|
c.chunkHeader.typ = ctCookieEcho
|
|
|
|
c.chunkHeader.raw = c.cookie
|
|
|
|
return c.chunkHeader.marshal()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *chunkCookieEcho) check() (abort bool, err error) {
|
|
|
|
return false, nil
|
|
|
|
}
|