1// +build !debug 2 3package stun 4 5import "github.com/pion/stun/internal/hmac" 6 7// CheckSize returns ErrAttrSizeInvalid if got is not equal to expected. 8func CheckSize(_ AttrType, got, expected int) error { 9 if got == expected { 10 return nil 11 } 12 return ErrAttributeSizeInvalid 13} 14 15func checkHMAC(got, expected []byte) error { 16 if hmac.Equal(got, expected) { 17 return nil 18 } 19 return ErrIntegrityMismatch 20} 21 22func checkFingerprint(got, expected uint32) error { 23 if got == expected { 24 return nil 25 } 26 return ErrFingerprintMismatch 27} 28 29// IsAttrSizeInvalid returns true if error means that attribute size is invalid. 30func IsAttrSizeInvalid(err error) bool { 31 return err == ErrAttributeSizeInvalid 32} 33 34// CheckOverflow returns ErrAttributeSizeOverflow if got is bigger that max. 35func CheckOverflow(_ AttrType, got, max int) error { 36 if got <= max { 37 return nil 38 } 39 return ErrAttributeSizeOverflow 40} 41 42// IsAttrSizeOverflow returns true if error means that attribute size is too big. 43func IsAttrSizeOverflow(err error) bool { 44 return err == ErrAttributeSizeOverflow 45} 46