-
Notifications
You must be signed in to change notification settings - Fork 96
/
checks.go
53 lines (43 loc) · 1.19 KB
/
checks.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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build !debug
// +build !debug
package stun
import (
"errors"
"github.com/pion/stun/v3/internal/hmac"
)
// CheckSize returns ErrAttrSizeInvalid if got is not equal to expected.
func CheckSize(_ AttrType, got, expected int) error {
if got == expected {
return nil
}
return ErrAttributeSizeInvalid
}
func checkHMAC(got, expected []byte) error {
if hmac.Equal(got, expected) {
return nil
}
return ErrIntegrityMismatch
}
func checkFingerprint(got, expected uint32) error {
if got == expected {
return nil
}
return ErrFingerprintMismatch
}
// IsAttrSizeInvalid returns true if error means that attribute size is invalid.
func IsAttrSizeInvalid(err error) bool {
return errors.Is(err, ErrAttributeSizeInvalid)
}
// CheckOverflow returns ErrAttributeSizeOverflow if got is bigger that max.
func CheckOverflow(_ AttrType, got, maxVal int) error {
if got <= maxVal {
return nil
}
return ErrAttributeSizeOverflow
}
// IsAttrSizeOverflow returns true if error means that attribute size is too big.
func IsAttrSizeOverflow(err error) bool {
return errors.Is(err, ErrAttributeSizeOverflow)
}