This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Correct writing of hexadecimal values Because WriteUtil.writeHexadecimal used Integer.toHexString which converts each byte into an integer and then writes that integer using the minimum required number of hexadecimal digits results would vary and negative bytes would be written using 8 hexadecimal digits with the first 6 being ffffff and positive bytes between 0 and 15 would only be written using 1 hexadecimal digit. This would cause the IV in EXT-X-KEY tags to be corrupted. Using String.format("%02x", b) instead means all bytes will be written correctly. They won't take up more than 2 characters since no integer-conversion is performed and if only 1 digit is required they will be zero-padded. * Added test for WriteUtil#writeHexadecimal * Correct parsing of hexadecimal values * Fixed failing testEXT_X_KEY The IV was too short and the expected value was wrong
- Loading branch information
1 parent
0c3d465
commit 7665c2a
Showing
5 changed files
with
112 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/com/iheartradio/m3u8/ParseUtilParseHexadecimalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2017, Spiideo | ||
*/ | ||
|
||
package com.iheartradio.m3u8; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
/** | ||
* @author Raniz | ||
* @since 02/08/17. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class ParseUtilParseHexadecimalTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {1}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList(new Object[][]{ | ||
{Arrays.asList((byte) 0), "0x00"}, | ||
{Arrays.asList((byte) 1), "0x01"}, | ||
{Arrays.asList((byte) -1), "0xff"}, | ||
{Arrays.asList((byte) -16), "0xf0"}, | ||
{Arrays.asList((byte) 0, (byte) 1), "0x0001"}, | ||
{Arrays.asList((byte) 1, (byte) 1), "0x0101"}, | ||
{Arrays.asList((byte) -1, (byte) -1), "0xffff"}, | ||
{Arrays.asList((byte) -121, (byte) -6), "0x87fa"}, | ||
{Arrays.asList((byte) 75, (byte) 118), "0x4b76"}, | ||
}); | ||
} | ||
|
||
private final List<Byte> expected; | ||
private final String input; | ||
|
||
public ParseUtilParseHexadecimalTest(final List<Byte> expected, final String input) { | ||
this.expected = expected; | ||
this.input = input; | ||
} | ||
|
||
@Test | ||
public void parseHexadecimal() throws Exception { | ||
Assert.assertEquals(expected, ParseUtil.parseHexadecimal(input, "")); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/com/iheartradio/m3u8/WriteUtilWriteHexadecimalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2017, Spiideo | ||
*/ | ||
|
||
package com.iheartradio.m3u8; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
/** | ||
* @author Raniz | ||
* @since 02/08/17. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class WriteUtilWriteHexadecimalTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {1}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList(new Object[][]{ | ||
{Arrays.asList((byte) 0), "0x00"}, | ||
{Arrays.asList((byte) 1), "0x01"}, | ||
{Arrays.asList((byte) -1), "0xff"}, | ||
{Arrays.asList((byte) -16), "0xf0"}, | ||
{Arrays.asList((byte) 0, (byte) 1), "0x0001"}, | ||
{Arrays.asList((byte) 1, (byte) 1), "0x0101"}, | ||
{Arrays.asList((byte) -1, (byte) -1), "0xffff"}, | ||
{Arrays.asList((byte) -121, (byte) -6), "0x87fa"}, | ||
{Arrays.asList((byte) 75, (byte) 118), "0x4b76"}, | ||
}); | ||
} | ||
|
||
private final List<Byte> input; | ||
private final String expected; | ||
|
||
public WriteUtilWriteHexadecimalTest(final List<Byte> input, final String expected) { | ||
this.input = input; | ||
this.expected = expected; | ||
} | ||
|
||
@Test | ||
public void writeHexadecimal() throws Exception { | ||
Assert.assertEquals(expected, WriteUtil.writeHexadecimal(input)); | ||
} | ||
|
||
} |