Skip to content

Commit

Permalink
Fix decode single byte and data is array
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Nov 7, 2019
1 parent b614b19 commit db513ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/RLP.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ protected function decodeData(string $input)

if ($firstByte <= 0x7f) {
return [
'data' => $firstByte,
'data' => dechex($firstByte),
'remainder' => mb_substr($input, 2)
];
} elseif ($firstByte <= 0xb7) {
$length = $firstByte - 0x7f;
$data = [];
$data = '';

if ($firstByte !== 0x80) {
$data = mb_substr($input, 2, ($length - 1) * 2);
Expand Down Expand Up @@ -113,7 +113,7 @@ protected function decodeData(string $input)
];
} elseif ($firstByte <= 0xf7) {
$length = $firstByte - 0xbf;
$innerRemainder = mb_substr($input, 2, $length * 2);
$innerRemainder = mb_substr($input, 2, ($length - 1) * 2);
$decoded = [];

while (mb_strlen($innerRemainder)) {
Expand All @@ -127,7 +127,7 @@ protected function decodeData(string $input)
];
} else {
$llength = $firstByte - 0xf6;
$hexLength = mb_substr($input, 2, $llength * 2);
$hexLength = mb_substr($input, 2, ($llength - 1) * 2);
$decoded = [];

if ($hexLength === '00') {
Expand Down
5 changes: 4 additions & 1 deletion test/unit/RLPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ public function testDecode()
$this->assertEquals(199999, hexdec($decoded[0]));
$this->assertEquals(1, hexdec($decoded[1]));

$encoded = '0x' . $rlp->encode('0x25');
$decoded = $rlp->decode($encoded);
$this->assertEquals('25', $decoded);
}

/**
* testValidRlp
*
*
* @return void
*/
public function testValidRlp()
Expand Down

0 comments on commit db513ab

Please sign in to comment.