Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #15 from Kami/improve_otp_decoding

Improve otp decoding
  • Loading branch information...
commit 680f27847074ea4fe4a6a787f72ff4e2d937fdf8 2 parents b9d9256 + 9756bfa
@Kami authored
View
8 CHANGES.md
@@ -1,3 +1,11 @@
+in development:
+
+* If there are multiple interpretations for a given OTP, first try to find the one
+ which matches the input OTP. If the one is found, use the input OTP, otherwise
+ use random interpretation. - https://github.com/Kami/python-yubico-client/issues/14
+
+ Reported by Klas Lindfors
+
1.6.1 - 2013-03-19:
* Only run `logging.basicConfig` when running tests so logging config isn't initialised
View
2  setup.py
@@ -41,7 +41,7 @@ class TestCommand(Command):
def initialize_options(self):
FORMAT = '%(asctime)-15s [%(levelname)s] %(message)s'
logging.basicConfig(format=FORMAT)
-
+
THIS_DIR = os.path.abspath(os.path.split(__file__)[0])
sys.path.insert(0, THIS_DIR)
for test_path in TEST_PATHS:
View
13 tests/test_yubico.py
@@ -20,6 +20,19 @@ def test_otp_class(self):
self.assertEqual(otp2.otp,
'ccccccccljdeluiucdgffccchkugjcfditgbglbflvjc')
+ def test_translation_multiple_interpretations(self):
+ otp_str1 = 'vvbtbtndhtlfguefgluvbdcetnitidgkvfkbicevgcin'
+ otp1 = OTP(otp_str1)
+ self.assertEqual(otp1.otp, otp_str1)
+
+ def test_translation_single_interpretation(self):
+ otp_str1 = 'cccfgvgitchndibrrtuhdrgeufrdkrjfgutfjbnhhglv'
+ otp_str2 = 'cccagvgitchndibrrtuhdrgeufrdkrjfgutfjbnhhglv'
+ otp1 = OTP(otp_str1)
+ otp2 = OTP(otp_str2)
+ self.assertEqual(otp1.otp, otp_str1)
+ self.assertEqual(otp2.otp, otp_str2)
+
class TestYubicoVerifySingle(unittest.TestCase):
def setUp(self):
View
2  yubico/__init__.py
@@ -1 +1 @@
-__version__ = (1, 6, 1)
+__version__ = (1, 6, 2, 'dev')
View
15 yubico/otp.py
@@ -20,11 +20,20 @@ def get_otp_modehex_interpretation(self, otp):
# if the OTP uses all 16 characters in its alphabet
# there is only one possible interpretation of that otp
try:
- otp_translated = modhex.translate(unicode(otp)).pop()
+ interpretations = modhex.translate(unicode(otp))
except Exception:
- otp_translated = otp
+ return otp
- return otp_translated
+ if len(interpretations) == 0:
+ return otp
+ elif len(interpretations) > 1:
+ # If there are multiple interpretations first try to use the same
+ # translation as the input OTP. If the one is not found, use the
+ # random interpretation.
+ if unicode(otp) in interpretations:
+ return otp
+
+ return interpretations.pop()
def __repr__(self):
return '%s, %s, %s' % (self.otp, self.device_id, self.timestamp)
Please sign in to comment.
Something went wrong with that request. Please try again.