| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp |
| 5 |
|
| 6 |
import ( |
| 7 |
"encoding/binary" |
| 8 |
"errors" |
| 9 |
) |
| 10 |
|
| 11 |
// This parameter is used to inform the receiver that a sender is willing to |
| 12 |
// accept zero as checksum if some other error detection method is used |
| 13 |
// instead. |
| 14 |
// |
| 15 |
// 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 |
| 16 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 17 |
// | Type = 0x8001 (suggested) | Length = 8 | |
| 18 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 19 |
// | Error Detection Method Identifier (EDMID) | |
| 20 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 21 |
|
| 22 |
type paramZeroChecksumAcceptable struct { |
| 23 |
paramHeader |
| 24 |
// The Error Detection Method Identifier (EDMID) specifies an alternate |
| 25 |
// error detection method the sender of this parameter is willing to use for |
| 26 |
// received packets. |
| 27 |
edmid uint32 |
| 28 |
} |
| 29 |
|
| 30 |
// Zero Checksum parameter error. |
| 31 |
var ( |
| 32 |
ErrZeroChecksumParamTooShort = errors.New("zero checksum parameter too short") |
| 33 |
) |
| 34 |
|
| 35 |
const ( |
| 36 |
dtlsErrorDetectionMethod uint32 = 1 |
| 37 |
) |
| 38 |
|
| 39 |
func (r *paramZeroChecksumAcceptable) marshal() ([]byte, error) { |
| 40 |
r.typ = zeroChecksumAcceptable |
| 41 |
r.raw = make([]byte, 4) |
| 42 |
binary.BigEndian.PutUint32(r.raw, r.edmid) |
| 43 |
|
| 44 |
return r.paramHeader.marshal() |
| 45 |
} |
| 46 |
|
| 47 |
func (r *paramZeroChecksumAcceptable) unmarshal(raw []byte) (param, error) { |
| 48 |
err := r.paramHeader.unmarshal(raw) |
| 49 |
if err != nil { |
| 50 |
return nil, err |
| 51 |
} |
| 52 |
if len(r.raw) < 4 { |
| 53 |
return nil, ErrZeroChecksumParamTooShort |
| 54 |
} |
| 55 |
r.edmid = binary.BigEndian.Uint32(r.raw) |
| 56 |
|
| 57 |
return r, nil |
| 58 |
} |