Skip to content

Commit

Permalink
Encoder validation simplified.
Browse files Browse the repository at this point in the history
  • Loading branch information
jocic committed Jan 17, 2019
1 parent 0ea60a5 commit eb051a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 63 deletions.
23 changes: 2 additions & 21 deletions source/Jocic/Encoders/Base/Base16.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,28 +245,9 @@ public function isEncodingValid($encoding)
return true;
}

// Step 2 - Check General Form
// Step 2 - Check Encoding

if (!preg_match("/^([A-z0-9]+)?$/", $encoding))
{
return false;
}

// Step 3 - Generate Character Array

$characters = str_split($encoding);

// Step 4 - Check Characters

foreach ($characters as $character)
{
if (!in_array($character, $baseTable))
{
return false;
}
}

return true;
return preg_match("/^([A-F0-7]+)([=]+)?$/", $encoding) == 1;
}

/********************\
Expand Down
23 changes: 2 additions & 21 deletions source/Jocic/Encoders/Base/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,9 @@ public function isEncodingValid($encoding)
return true;
}

// Step 2 - Check General Form
// Step 2 - Check Encoding

if (!preg_match("/^([A-z0-9]+)([=]+)?$/", $encoding))
{
return false;
}

// Step 3 - Trim Padding & Generate Array

$characters = str_split(rtrim($encoding, $basePadding));

// Step 4 - Check Characters

foreach ($characters as $character)
{
if (!in_array($character, $baseTable))
{
return false;
}
}

return true;
return preg_match("/^([A-Z2-7]+)([=]+)?$/", $encoding) == 1;
}

/********************\
Expand Down
23 changes: 2 additions & 21 deletions source/Jocic/Encoders/Base/Base64.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,9 @@ public function isEncodingValid($encoding)
return true;
}

// Step 2 - Check General Form
// Step 2 - Check Encoding

if (!preg_match("/^([A-z0-9]+)([=]+)?$/", $encoding))
{
return false;
}

// Step 3 - Trim Padding & Generate Array

$characters = str_split(rtrim($encoding, $basePadding));

// Step 4 - Check Characters

foreach ($characters as $character)
{
if (!in_array($character, $baseTable))
{
return false;
}
}

return true;
return preg_match("/^([A-z0-9+\/]+)([=]+)?$/", $encoding) == 1;
}

/********************\
Expand Down

0 comments on commit eb051a3

Please sign in to comment.