Repository: pion/rtp
Pull request #64 (2020-05-18 20:10:33)

Fix SetExtension ExtensionProfile for 16byte extension
Fix when using `SetExtension` with 16byte header extension.


codecov[bot]: # [Codecov](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=h1) Report
> Merging [#64](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=desc) into [master](https://codecov.io/gh/pion/rtp/commit/c23812f8c9034d180c05430d71babea3d4e2db26&el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/pion/rtp/pull/64/graphs/tree.svg?width=650&height=150&src=pr&token=4KrbiBsspj)](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master      #64   +/-   ##
=======================================
  Coverage   90.86%   90.86%           
=======================================
  Files          13       13           
  Lines         635      635           
=======================================
  Hits          577      577           
  Misses         41       41           
  Partials       17       17           
```

| Flag | Coverage Δ | |
|---|---|---|
| #go | `90.86% <100.00%> (ø)` | |
| #wasm | `90.86% <100.00%> (ø)` | |

| [Impacted Files](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packet.go](https://codecov.io/gh/pion/rtp/pull/64/diff?src=pr&el=tree#diff-cGFja2V0Lmdv) | `83.48% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=footer). Last update [c23812f...e706e72](https://codecov.io/gh/pion/rtp/pull/64?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packet.go b/packet.go
index ff6bd2a..b0e5777 100644
--- a/packet.go
+++ b/packet.go
@@ -393,7 +393,7 @@ func (h *Header) SetExtension(id uint8, payload []byte) error {
 	h.Extension = true
 
 	switch len := len(payload); {
-	case len < 16:
+	case len <= 16:
 		h.ExtensionProfile = extensionProfileOneByte
 	case len > 16 && len < 256:
 		h.ExtensionProfile = extensionProfileTwoByte


Test patch:
diff --git a/packet_test.go b/packet_test.go
index a5f502f..add250d 100644
--- a/packet_test.go
+++ b/packet_test.go
@@ -613,6 +613,41 @@ func TestRFC8285OneByteSetExtensionShouldEnableExensionsWhenAdding(t *testing.T)
 	}
 }
 
+func TestRFC8285OneByteSetExtensionShouldSetCorrectExtensionProfileFor16ByteExtension(t *testing.T) {
+	payload := []byte{
+		// Payload
+		0x98, 0x36, 0xbe, 0x88, 0x9e,
+	}
+	p := &Packet{Header: Header{
+		Marker:         true,
+		Extension:      false,
+		Version:        2,
+		PayloadOffset:  26,
+		PayloadType:    96,
+		SequenceNumber: 27023,
+		Timestamp:      3653407706,
+		SSRC:           476325762,
+		CSRC:           []uint32{},
+	},
+		Payload: payload,
+	}
+
+	extension := []byte{
+		0xAA, 0xAA, 0xAA, 0xAA,
+		0xAA, 0xAA, 0xAA, 0xAA,
+		0xAA, 0xAA, 0xAA, 0xAA,
+		0xAA, 0xAA, 0xAA, 0xAA,
+	}
+	err := p.SetExtension(1, extension)
+	if err != nil {
+		t.Error("Error setting extension")
+	}
+
+	if p.ExtensionProfile != 0xBEDE {
+		t.Error("Extension profile should be set to 0xBEDE")
+	}
+}
+
 func TestRFC8285OneByteSetExtensionShouldUpdateExistingExension(t *testing.T) {
 	payload := []byte{
 		// Payload