1// +build debug 2 3package stun 4 5import "github.com/pion/stun/internal/hmac" 6 7// CheckSize returns *AttrLengthError if got is not equal to expected. 8func CheckSize(a AttrType, got, expected int) error { 9 if got == expected { 10 return nil 11 } 12 return &AttrLengthErr{ 13 Got: got, 14 Expected: expected, 15 Attr: a, 16 } 17} 18 19func checkHMAC(got, expected []byte) error { 20 if hmac.Equal(got, expected) { 21 return nil 22 } 23 return &IntegrityErr{ 24 Expected: expected, 25 Actual: got, 26 } 27} 28 29func checkFingerprint(got, expected uint32) error { 30 if got == expected { 31 return nil 32 } 33 return &CRCMismatch{ 34 Actual: got, 35 Expected: expected, 36 } 37} 38 39// IsAttrSizeInvalid returns true if error means that attribute size is invalid. 40func IsAttrSizeInvalid(err error) bool { 41 _, ok := err.(*AttrLengthErr) 42 return ok 43} 44 45// CheckOverflow returns *AttrOverflowErr if got is bigger that max. 46func CheckOverflow(t AttrType, got, max int) error { 47 if got <= max { 48 return nil 49 } 50 return &AttrOverflowErr{ 51 Type: t, 52 Got: got, 53 Max: max, 54 } 55} 56 57// IsAttrSizeOverflow returns true if error means that attribute size is too big. 58func IsAttrSizeOverflow(err error) bool { 59 _, ok := err.(*AttrOverflowErr) 60 return ok 61} 62