diff options
| author | Ayrx <terrycwk1994@gmail.com> | 2014-02-12 22:22:01 +0800 |
|---|---|---|
| committer | Ayrx <terrycwk1994@gmail.com> | 2014-02-21 11:13:35 +0800 |
| commit | b2ee044298caf5772fb8774dc691add3afe8cdc1 (patch) | |
| tree | 151583dbe983c8265d6ef13795d0a23bbacdc6c7 /cryptography | |
| parent | 18ca44bfef0fe2908d9da3b3008941325d04a971 (diff) | |
| download | cryptography-b2ee044298caf5772fb8774dc691add3afe8cdc1.tar.gz cryptography-b2ee044298caf5772fb8774dc691add3afe8cdc1.tar.bz2 cryptography-b2ee044298caf5772fb8774dc691add3afe8cdc1.zip | |
Minor changes for python3 compat and documentation changes
Diffstat (limited to 'cryptography')
| -rw-r--r-- | cryptography/hazmat/oath/hotp.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/cryptography/hazmat/oath/hotp.py b/cryptography/hazmat/oath/hotp.py index 319e66f2..a04d0d49 100644 --- a/cryptography/hazmat/oath/hotp.py +++ b/cryptography/hazmat/oath/hotp.py @@ -12,6 +12,7 @@ # limitations under the License. import struct +import six from cryptography.hazmat.primitives import constant_time from cryptography.hazmat.primitives.hashes import SHA1 @@ -25,7 +26,8 @@ class HOTP(object): def generate(self, counter): sbit = self._dynamic_truncate(counter) - return str(sbit % (10**self.length)).zfill(self.length) + foo = sbit % (10**self.length) + return ('%s' % foo).zfill(self.length).encode() def verify(self, hotp, counter): return constant_time.bytes_eq(self.generate(counter), hotp) @@ -35,7 +37,8 @@ class HOTP(object): ctx.update(struct.pack(">Q", counter)) hmac_value = ctx.finalize() - offset_bits = ord(hmac_value[19]) & 0b1111 + offset_bits = six.indexbytes(hmac_value, 19) & 0b1111 + offset = int(offset_bits) P = hmac_value[offset:offset+4] return struct.unpack(">I", P)[0] & 0x7fffffff |
