* Added some base32 decoding-specific unittests

* Base32 decoding now allows for padding chars
This commit is contained in:
RobThree
2015-03-22 23:46:15 +01:00
parent fad49deb8c
commit 74a18a8fa6
2 changed files with 69 additions and 1 deletions
+5 -1
View File
@@ -12,6 +12,7 @@ class TwoFactorAuth
private $issuer;
private $qrcodeprovider;
private $rngprovider;
private static $_base32dict = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=';
private static $_base32;
private static $_base32lookup = array();
private static $_supportedalgos = array('sha1', 'sha256', 'sha512', 'md5');
@@ -60,7 +61,7 @@ class TwoFactorAuth
$this->rngprovider = $rngprovider;
self::$_base32 = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=');
self::$_base32 = str_split(self::$_base32dict);
self::$_base32lookup = array_flip(self::$_base32);
}
@@ -151,6 +152,9 @@ class TwoFactorAuth
{
if (strlen($value)==0) return '';
if (preg_match('/[^'.preg_quote(self::$_base32dict).']/', $value) !== 0)
throw new TwoFactorAuthException('Invalid base32 string');
$s = '';
foreach (str_split($value) as $c)
{