-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathparam_zero_checksum.go
More file actions
68 lines (55 loc) · 1.98 KB
/
Copy pathparam_zero_checksum.go
File metadata and controls
68 lines (55 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"encoding/binary"
"errors"
)
// This parameter is used to inform the receiver that a sender is willing to
// accept zero as checksum if some other error detection method is used
// instead. See RFC 9653 section 4.
//
// 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 = 0x8001 (suggested) | Length = 8 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Error Detection Method Identifier (EDMID) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
type paramZeroChecksumAcceptable struct {
paramHeader
// The Error Detection Method Identifier (EDMID) specifies an alternate
// error detection method the sender of this parameter is willing to use for
// received packets.
edmid uint32
}
// Zero Checksum parameter error.
var (
ErrZeroChecksumParamTooShort = errors.New("zero checksum parameter too short")
// RFC 9653 section 4: Length MUST be 8.
ErrZeroChecksumParamInvalidLength = errors.New("zero checksum parameter length must be 8")
)
const (
dtlsErrorDetectionMethod uint32 = 1
)
func (r *paramZeroChecksumAcceptable) marshal() ([]byte, error) {
r.typ = zeroChecksumAcceptable
r.raw = make([]byte, 4)
binary.BigEndian.PutUint32(r.raw, r.edmid)
return r.paramHeader.marshal()
}
func (r *paramZeroChecksumAcceptable) unmarshal(raw []byte) (param, error) {
err := r.paramHeader.unmarshal(raw)
if err != nil {
return nil, err
}
// Enforce exact length: header.len MUST be 8 (RFC 9653 section 4).
if r.len != 8 {
return nil, ErrZeroChecksumParamInvalidLength
}
// Raw value bytes MUST be exactly 4 bytes (since len=8 -> 4-byte header + 4-byte EDMID).
if len(r.raw) != 4 {
return nil, ErrZeroChecksumParamTooShort
}
r.edmid = binary.BigEndian.Uint32(r.raw)
return r, nil
}