From 99ff0f49d3f668acf4a7d9e7f4da275a1cb327c2 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 16 May 2020 10:04:13 -0400 Subject: Match v5 partial fingerprints from front rather than back. --- lib/KeyDB.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/KeyDB.hs') diff --git a/lib/KeyDB.hs b/lib/KeyDB.hs index fc20b91..f785f8e 100644 --- a/lib/KeyDB.hs +++ b/lib/KeyDB.hs @@ -76,11 +76,18 @@ fingerprintGrip (Fingerprint bs) = -- -- The above was removed because Int is encoded as 8 bytes even when we are -- -- using 32-bit GHC. -- Presumably, the extra 4 bytes will be truncated. - case decode $ L.fromStrict $ S.drop (S.length bs - 8) bs of - i -> KeyInt i + case S.length bs of + -- v5 from the front + 32 -> case decode $ L.fromStrict bs of + i -> KeyInt i + -- v4 from the back + l -> case decode $ L.fromStrict $ S.drop (l - 8) bs of + i -> KeyInt i smallprGrip :: String -> Maybe KeyGrip -smallprGrip pr = KeyInt <$> readMaybe ("0x" ++ drop (length pr - 2 * sizeOf (0::Int)) pr) +smallprGrip pr = case length pr of + 64 -> KeyInt <$> readMaybe ("0x" ++ take (2 * sizeOf (0::Int)) pr) + l -> KeyInt <$> readMaybe ("0x" ++ drop (l - 2 * sizeOf (0::Int)) pr) data KeyDB = KeyDB { byKeyKey :: Map.Map KeyKey KeyData -- cgit v1.2.3