hnix-store-{core,remote}: support both base16-bytestring epochs

This commit is contained in:
Anton-Latukha 2020-12-30 13:46:56 +02:00
parent 43313d0870
commit 3ece3b4e50
No known key found for this signature in database
GPG Key ID: 3D84C07E91802E41
2 changed files with 16 additions and 3 deletions

View File

@ -162,7 +162,7 @@ decodeBase :: BaseEncoding -> T.Text -> Either String (Digest a)
#if MIN_VERSION_base16_bytestring(1,0,0)
decodeBase Base16 = fmap Digest . Base16.decode . T.encodeUtf8
#else
decodeBase Base16 = lDecode -- *this tacit sugar simply makes GHC pleased with number of args
decodeBase Base16 = lDecode -- this tacit sugar simply makes GHC pleased with number of args
where
lDecode t = case Base16.decode (T.encodeUtf8 t) of
(x, "") -> Right $ Digest x

View File

@ -2,6 +2,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE CPP #-}
module Hash where
@ -91,7 +92,19 @@ spec_nixhash = do
forM_ samples $ \(b16, b32, b64) -> shouldBe (B16.encode . BSL.toStrict <$> B64.decode b64 ) (Right b16)
it "b32 encoded . b16 decoded should equal original b32" $
forM_ samples $ \(b16, b32, b64) -> shouldBe (B32.encode <$> B16.decode b16) (Right b32)
forM_ samples $ \(b16, b32, b64) -> shouldBe (B32.encode
#if MIN_VERSION_base16_bytestring(1,0,0)
<$> B16.decode b16) (Right b32)
#else
$ fst $ B16.decode b16) (b32)
#endif
it "b64 encoded . b16 decoded should equal original b64" $
forM_ samples $ \(b16, b32, b64) -> shouldBe (B64.encode . BSL.fromStrict <$> B16.decode b16 ) (Right b64)
forM_ samples $ \(b16, b32, b64) -> shouldBe (B64.encode . BSL.fromStrict
#if MIN_VERSION_base16_bytestring(1,0,0)
<$> B16.decode b16) (Right b64)
#else
$ fst $ B16.decode b16 ) (b64)
#endif