mirror of
https://github.com/pion/stun.git
synced 2025-12-24 11:51:03 +08:00
Add AttrType.Known method
Will allow us to check in pion/turn if a Attribute has been implemented. We should be returning errors if a client returns a unknown attribute Relates to pion/turn#76
This commit is contained in:
@@ -171,6 +171,14 @@ func (t AttrType) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
// Known returns true if AttrType is known and implemented
|
||||
// by this library.
|
||||
func (t AttrType) Known() bool {
|
||||
_, valid := attrNames()[t]
|
||||
|
||||
return valid
|
||||
}
|
||||
|
||||
// RawAttribute is a Type-Length-Value (TLV) object that
|
||||
// can be added to a STUN message. Attributes are divided into two
|
||||
// types: comprehension-required and comprehension-optional. STUN
|
||||
|
||||
@@ -107,3 +107,12 @@ func TestAttrTypeRange(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttrTypeKnown(t *testing.T) {
|
||||
// All Attributes in attrNames should be known
|
||||
for attr := range attrNames() {
|
||||
assert.True(t, attr.Known())
|
||||
}
|
||||
|
||||
assert.False(t, AttrType(0xFFFF).Known()) // Known
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user