Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 20, 2013
@Kami Not working on 1.6.2-dev 7fc5f9f
Commits on Mar 30, 2013
@Kami If there are multiple interpretations for a given OTP, first try to f…
…ind the one

which matches the input OTP. If the one is found, use the input OTP, otherwise
use last of the available interpretations.

Reported by Klas Lindfors, part of #14.
d02510a
@Kami last -> random (.pop() on a set returns a random item). 9756bfa
Commits on Apr 02, 2013
@Kami Merge pull request #15 from Kami/improve_otp_decoding
Improve otp decoding
680f278
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)

No commit comments for this range

Something went wrong with that request. Please try again.