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 =
|
||||
case Base16.decode (T.encodeUtf8 t) of
|
||||
(x, "") -> pure $ x
|
||||
_ -> Left $ "Unable to decode base16 string" <> T.unpack t
|
||||
_ -> Left $ "Unable to decode base16 string" <> toString t
|
||||
#endif
|
||||
decodeWith NixBase32 = Base32.decode
|
||||
decodeWith Base64 = Base64.decode . T.encodeUtf8
|
||||
|
@ -68,7 +68,7 @@ unsafeDecode what =
|
||||
(\c -> fromMaybe (error "character not in digits32")
|
||||
$ Vector.findIndex (== c) digits32
|
||||
)
|
||||
(Data.Text.unpack what)
|
||||
(toString what)
|
||||
of
|
||||
[(i, _)] -> pure $ padded $ integerToBS i
|
||||
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
|
||||
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 name sriHash =
|
||||
let (sriName, h) = T.breakOnEnd "-" sriHash in
|
||||
if sriName == "" || sriName == name <> "-"
|
||||
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
|
||||
mkDigest h = case name of
|
||||
"md5" -> SomeDigest <$> decodeGo C.MD5 h
|
||||
"sha1" -> SomeDigest <$> decodeGo C.SHA1 h
|
||||
"sha256" -> SomeDigest <$> decodeGo C.SHA256 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 a h
|
||||
| size == base16Len = decodeDigestWith Base16 h
|
||||
| size == base32Len = decodeDigestWith NixBase32 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
|
||||
size = T.length h
|
||||
hsize = C.hashDigestSize a
|
||||
|
@ -166,7 +166,7 @@ parseSymlink = do
|
||||
(dir, file) <- currentDirectoryAndFile
|
||||
pushLink $
|
||||
LinkInfo
|
||||
{ linkTarget = Text.unpack target
|
||||
{ linkTarget = toString target
|
||||
, linkFile = file
|
||||
, linkPWD = dir
|
||||
}
|
||||
@ -271,7 +271,7 @@ parseDirectory = do
|
||||
parens $ do
|
||||
expectStr "name"
|
||||
fName <- parseStr
|
||||
pushFileName (Text.unpack fName)
|
||||
pushFileName (toString fName)
|
||||
expectStr "node"
|
||||
parens parseFSO
|
||||
popFileName
|
||||
|
Loading…
Reference in New Issue
Block a user