This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
param_zero_checksum.go
56 lines (48 loc) · 1.59 KB
/
param_zero_checksum.go
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
// SPDX-FileCopyrightText: 2023 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.
//
// 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")
)
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
}
if len(r.raw) < 4 {
return nil, ErrZeroChecksumParamTooShort
}
r.edmid = binary.BigEndian.Uint32(r.raw)
return r, nil
}