mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-12-14 19:47:56 +03:00
treewide: use toString
This commit is contained in:
parent
99da38fa83
commit
0789f253c8
@ -39,7 +39,7 @@ decodeWith Base16 = lDecode -- this tacit sugar simply makes GHC pleased with n
|
|||||||
lDecode t =
|
lDecode t =
|
||||||
case Base16.decode (T.encodeUtf8 t) of
|
case Base16.decode (T.encodeUtf8 t) of
|
||||||
(x, "") -> pure $ x
|
(x, "") -> pure $ x
|
||||||
_ -> Left $ "Unable to decode base16 string" <> T.unpack t
|
_ -> Left $ "Unable to decode base16 string" <> toString t
|
||||||
#endif
|
#endif
|
||||||
decodeWith NixBase32 = Base32.decode
|
decodeWith NixBase32 = Base32.decode
|
||||||
decodeWith Base64 = Base64.decode . T.encodeUtf8
|
decodeWith Base64 = Base64.decode . T.encodeUtf8
|
||||||
|
@ -68,7 +68,7 @@ unsafeDecode what =
|
|||||||
(\c -> fromMaybe (error "character not in digits32")
|
(\c -> fromMaybe (error "character not in digits32")
|
||||||
$ Vector.findIndex (== c) digits32
|
$ Vector.findIndex (== c) digits32
|
||||||
)
|
)
|
||||||
(Data.Text.unpack what)
|
(toString what)
|
||||||
of
|
of
|
||||||
[(i, _)] -> pure $ padded $ integerToBS i
|
[(i, _)] -> pure $ padded $ integerToBS i
|
||||||
x -> Left $ "Can't decode: readInt returned " <> show x
|
x -> Left $ "Can't decode: readInt returned " <> show x
|
||||||
|
@ -49,27 +49,27 @@ data SomeNamedDigest = forall a . NamedAlgo a => SomeDigest (C.Digest a)
|
|||||||
|
|
||||||
instance Show SomeNamedDigest where
|
instance Show SomeNamedDigest where
|
||||||
show sd = case sd of
|
show sd = case sd of
|
||||||
SomeDigest (digest :: C.Digest hashType) -> T.unpack $ "SomeDigest " <> algoName @hashType <> ":" <> encodeDigestWith NixBase32 digest
|
SomeDigest (digest :: C.Digest hashType) -> toString $ "SomeDigest " <> algoName @hashType <> ":" <> encodeDigestWith NixBase32 digest
|
||||||
|
|
||||||
mkNamedDigest :: Text -> Text -> Either String SomeNamedDigest
|
mkNamedDigest :: Text -> Text -> Either String SomeNamedDigest
|
||||||
mkNamedDigest name sriHash =
|
mkNamedDigest name sriHash =
|
||||||
let (sriName, h) = T.breakOnEnd "-" sriHash in
|
let (sriName, h) = T.breakOnEnd "-" sriHash in
|
||||||
if sriName == "" || sriName == name <> "-"
|
if sriName == "" || sriName == name <> "-"
|
||||||
then mkDigest h
|
then mkDigest h
|
||||||
else Left $ T.unpack $ "Sri hash method " <> sriName <> " does not match the required hash type " <> name
|
else Left $ toString $ "Sri hash method " <> sriName <> " does not match the required hash type " <> name
|
||||||
where
|
where
|
||||||
mkDigest h = case name of
|
mkDigest h = case name of
|
||||||
"md5" -> SomeDigest <$> decodeGo C.MD5 h
|
"md5" -> SomeDigest <$> decodeGo C.MD5 h
|
||||||
"sha1" -> SomeDigest <$> decodeGo C.SHA1 h
|
"sha1" -> SomeDigest <$> decodeGo C.SHA1 h
|
||||||
"sha256" -> SomeDigest <$> decodeGo C.SHA256 h
|
"sha256" -> SomeDigest <$> decodeGo C.SHA256 h
|
||||||
"sha512" -> SomeDigest <$> decodeGo C.SHA512 h
|
"sha512" -> SomeDigest <$> decodeGo C.SHA512 h
|
||||||
_ -> Left $ "Unknown hash name: " <> T.unpack name
|
_ -> Left $ "Unknown hash name: " <> toString name
|
||||||
decodeGo :: forall a . NamedAlgo a => a -> Text -> Either String (C.Digest a)
|
decodeGo :: forall a . NamedAlgo a => a -> Text -> Either String (C.Digest a)
|
||||||
decodeGo a h
|
decodeGo a h
|
||||||
| size == base16Len = decodeDigestWith Base16 h
|
| size == base16Len = decodeDigestWith Base16 h
|
||||||
| size == base32Len = decodeDigestWith NixBase32 h
|
| size == base32Len = decodeDigestWith NixBase32 h
|
||||||
| size == base64Len = decodeDigestWith Base64 h
|
| size == base64Len = decodeDigestWith Base64 h
|
||||||
| otherwise = Left $ T.unpack sriHash <> " is not a valid " <> T.unpack name <> " hash. Its length (" <> show size <> ") does not match any of " <> show [base16Len, base32Len, base64Len]
|
| otherwise = Left $ toString sriHash <> " is not a valid " <> toString name <> " hash. Its length (" <> show size <> ") does not match any of " <> show [base16Len, base32Len, base64Len]
|
||||||
where
|
where
|
||||||
size = T.length h
|
size = T.length h
|
||||||
hsize = C.hashDigestSize a
|
hsize = C.hashDigestSize a
|
||||||
|
@ -166,7 +166,7 @@ parseSymlink = do
|
|||||||
(dir, file) <- currentDirectoryAndFile
|
(dir, file) <- currentDirectoryAndFile
|
||||||
pushLink $
|
pushLink $
|
||||||
LinkInfo
|
LinkInfo
|
||||||
{ linkTarget = Text.unpack target
|
{ linkTarget = toString target
|
||||||
, linkFile = file
|
, linkFile = file
|
||||||
, linkPWD = dir
|
, linkPWD = dir
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ parseDirectory = do
|
|||||||
parens $ do
|
parens $ do
|
||||||
expectStr "name"
|
expectStr "name"
|
||||||
fName <- parseStr
|
fName <- parseStr
|
||||||
pushFileName (Text.unpack fName)
|
pushFileName (toString fName)
|
||||||
expectStr "node"
|
expectStr "node"
|
||||||
parens parseFSO
|
parens parseFSO
|
||||||
popFileName
|
popFileName
|
||||||
|
Loading…
Reference in New Issue
Block a user