diff --git a/attributes.go b/attributes.go index 7db0e23..de1ba77 100644 --- a/attributes.go +++ b/attributes.go @@ -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 diff --git a/attributes_test.go b/attributes_test.go index a12a01d..5b229f9 100644 --- a/attributes_test.go +++ b/attributes_test.go @@ -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 +}