Make OTP resynch values a tuple

This is clearer than having two separate arguments.
This commit is contained in:
Luke Taylor 2015-12-27 18:43:00 +00:00
parent c5b3622562
commit 48f0598cc7
2 changed files with 7 additions and 8 deletions

View File

@ -33,7 +33,7 @@ hotp d k c = dt `mod` digitsPower d
fromIntegral (B.index mac (offset + 3) .&. 0xff) fromIntegral (B.index mac (offset + 3) .&. 0xff)
-- | Attempt to resynchronize the server's counter value -- | Attempt to resynchronize the server's counter value
-- with the client, given a sequence of HOTP values -- with the client, given a sequence of HOTP values.
resynchronize :: ByteArrayAccess key resynchronize :: ByteArrayAccess key
=> OTPDigits => OTPDigits
-> Word32 -> Word32
@ -43,14 +43,13 @@ resynchronize :: ByteArrayAccess key
-- ^ The shared secret -- ^ The shared secret
-> Word64 -> Word64
-- ^ The current server counter value -- ^ The current server counter value
-> Word32 -> (Word32, [Word32])
-- ^ The first OTP submitted by the client -- ^ The first OTP submitted by the client and a list of additional
-> [Word32] -- sequential OTPs (which may be empty)
-- ^ Additional sequential OTPs (may be empty)
-> Maybe Word64 -> Maybe Word64
-- ^ The new counter value, synchronized with the client's current counter -- ^ The new counter value, synchronized with the client's current counter
-- or Nothing if the submitted OTP values didn't match -- or Nothing if the submitted OTP values didn't match anywhere within the window
resynchronize d s k c p1 extras = do resynchronize d s k c (p1, extras) = do
offBy <- fmap fromIntegral (elemIndex p1 range) offBy <- fmap fromIntegral (elemIndex p1 range)
checkExtraOtps (c + offBy + 1) extras checkExtraOtps (c + offBy + 1) extras
where where

View File

@ -38,7 +38,7 @@ makeKATs = concatMap makeTest (zip3 is counts hotps)
] ]
-- resynching with the expected value should just return the current counter + 1 -- resynching with the expected value should just return the current counter + 1
prop_resyncExpected ctr window = resynchronize OTP6 window key ctr otp [] == Just (ctr + 1) prop_resyncExpected ctr window = resynchronize OTP6 window key ctr (otp, []) == Just (ctr + 1)
where where
key = "1234" :: ByteString key = "1234" :: ByteString
otp = hotp OTP6 key ctr otp = hotp OTP6 key ctr