mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 09:47:06 +00:00
Stop depending on package SHA
Pandoc already depends on `crypton-conntection`, and thus transitively on `crypton`. The latter provides a vast variety of hashing algorithms and makes the dependency on SHA unnecessary.
This commit is contained in:
@@ -105,9 +105,9 @@ library
|
||||
, Text.Pandoc.Lua.Writer.Classic
|
||||
, Text.Pandoc.Lua.Writer.Scaffolding
|
||||
|
||||
build-depends: SHA >= 1.6 && < 1.7
|
||||
, aeson
|
||||
build-depends: aeson
|
||||
, bytestring >= 0.9 && < 0.13
|
||||
, crypton >= 0.30 && < 1.1
|
||||
, citeproc >= 0.8 && < 0.9
|
||||
, containers >= 0.6.0.1 && < 0.8
|
||||
, data-default >= 0.4 && < 0.8
|
||||
|
||||
@@ -19,6 +19,7 @@ module Text.Pandoc.Lua.Module.Utils
|
||||
|
||||
import Control.Applicative ((<|>))
|
||||
import Control.Monad ((<$!>))
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import Data.Data (showConstr, toConstr)
|
||||
import Data.Default (def)
|
||||
import Data.Maybe (fromMaybe)
|
||||
@@ -34,8 +35,6 @@ import Text.Pandoc.Lua.Marshal.AST
|
||||
import Text.Pandoc.Lua.Marshal.Reference
|
||||
import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua))
|
||||
|
||||
import qualified Data.Digest.Pure.SHA as SHA
|
||||
import qualified Data.ByteString.Lazy as BSL
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Text as T
|
||||
import qualified Text.Pandoc.Builder as B
|
||||
@@ -301,8 +300,8 @@ run_json_filter = defun "run_json_filter"
|
||||
-- | Documented Lua function to compute the hash of a string.
|
||||
sha1 :: DocumentedFunction e
|
||||
sha1 = defun "sha1"
|
||||
### liftPure (SHA.showDigest . SHA.sha1)
|
||||
<#> parameter (fmap BSL.fromStrict . peekByteString) "string" "input" ""
|
||||
### liftPure (show . hashWith SHA1)
|
||||
<#> parameter peekByteString "string" "input" ""
|
||||
=#> functionResult pushString "string" "hexadecimal hash value"
|
||||
#? "Computes the SHA1 hash of the given string input."
|
||||
|
||||
|
||||
+1
-1
@@ -472,7 +472,6 @@ library
|
||||
build-depends: xml-light,
|
||||
Glob >= 0.7 && < 0.11,
|
||||
JuicyPixels >= 3.1.6.1 && < 3.4,
|
||||
SHA >= 1.6 && < 1.7,
|
||||
aeson >= 2.0.1.0 && < 2.3,
|
||||
aeson-pretty >= 0.8.9 && < 0.9,
|
||||
array >= 0.5 && < 0.6,
|
||||
@@ -488,6 +487,7 @@ library
|
||||
commonmark-extensions >= 0.2.5.5 && < 0.3,
|
||||
commonmark-pandoc >= 0.2.2.1 && < 0.3,
|
||||
containers >= 0.6.0.1 && < 0.8,
|
||||
crypton >= 0.30 && < 1.1,
|
||||
crypton-connection >= 0.3.1 && < 0.5,
|
||||
data-default >= 0.4 && < 0.8,
|
||||
deepseq >= 1.3 && < 1.6,
|
||||
|
||||
@@ -23,20 +23,19 @@ module Text.Pandoc.MediaBag (
|
||||
mediaDirectory,
|
||||
mediaItems
|
||||
) where
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
import Data.Data (Data)
|
||||
import qualified Data.Map as M
|
||||
import Data.Maybe (fromMaybe, isNothing)
|
||||
import Data.Typeable (Typeable)
|
||||
import Network.URI (unEscapeString)
|
||||
import System.FilePath
|
||||
import qualified System.FilePath.Posix as Posix
|
||||
import qualified System.FilePath.Windows as Windows
|
||||
import Text.Pandoc.MIME (MimeType, getMimeTypeDef, extensionFromMimeType)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Digest.Pure.SHA (sha1, showDigest)
|
||||
import Network.URI (URI (..), parseURI, isURI)
|
||||
import Network.URI (URI (..), isURI, parseURI, unEscapeString)
|
||||
import Data.List (isInfixOf)
|
||||
|
||||
data MediaItem =
|
||||
@@ -92,7 +91,7 @@ insertMedia fp mbMime contents (MediaBag mediamap) =
|
||||
&& not (".." `isInfixOf` fp'')
|
||||
&& '%' `notElem` fp''
|
||||
then fp''
|
||||
else showDigest (sha1 contents) <> ext
|
||||
else show (hashWith SHA1 $ BL.toStrict contents) <> ext
|
||||
fallback = case takeExtension fp'' of
|
||||
".gz" -> getMimeTypeDef $ dropExtension fp''
|
||||
_ -> getMimeTypeDef fp''
|
||||
|
||||
@@ -20,6 +20,7 @@ import qualified Codec.Picture as JP
|
||||
import qualified Control.Exception as E
|
||||
import Control.Monad.Trans (MonadIO (..))
|
||||
import Control.Monad (foldM_)
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.ByteString.Lazy (ByteString)
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
@@ -52,7 +53,6 @@ import qualified Text.Pandoc.UTF8 as UTF8
|
||||
import Text.Pandoc.Walk (walkM)
|
||||
import Text.Pandoc.Writers.Shared (getField, metaToContext)
|
||||
import Control.Monad.Catch (MonadMask)
|
||||
import Data.Digest.Pure.SHA (sha1, showDigest)
|
||||
#ifdef _WINDOWS
|
||||
import Data.List (intercalate)
|
||||
#endif
|
||||
@@ -236,7 +236,7 @@ convertImage opts tmpdir fname = do
|
||||
E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
|
||||
\(e :: E.SomeException) -> return (Left (tshow e))
|
||||
where
|
||||
sha = showDigest (sha1 (UTF8.fromStringLazy fname))
|
||||
sha = show (hashWith SHA1 (UTF8.fromString fname))
|
||||
pngOut = normalise $ tmpdir </> sha <.> "png"
|
||||
pdfOut = normalise $ tmpdir </> sha <.> "pdf"
|
||||
svgIn = normalise fname
|
||||
@@ -434,8 +434,8 @@ runTeXProgram program args tmpDir outDir = do
|
||||
tocFileExists <- fileExists tocFile
|
||||
if tocFileExists
|
||||
then do
|
||||
tocContents <- BL.fromStrict <$> readFileStrict tocFile
|
||||
pure $ Just $! sha1 tocContents
|
||||
tocContents <- readFileStrict tocFile
|
||||
pure $ Just $! hashWith SHA1 tocContents
|
||||
else pure Nothing
|
||||
-- compare hash of toc to former hash to see if it changed (#9295)
|
||||
let rerunWarnings' = rerunWarnings ++
|
||||
|
||||
@@ -15,9 +15,9 @@ Ipynb (Jupyter notebook JSON format) reader for pandoc.
|
||||
-}
|
||||
module Text.Pandoc.Readers.Ipynb ( readIpynb )
|
||||
where
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import Data.Char (isDigit)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Digest.Pure.SHA (sha1, showDigest)
|
||||
import Text.Pandoc.Options
|
||||
import Control.Applicative ((<|>))
|
||||
import qualified Data.Scientific as Scientific
|
||||
@@ -186,16 +186,16 @@ handleData (JSONMeta metadata) (MimeBundle mb) =
|
||||
Error _ -> mempty
|
||||
_ -> mempty
|
||||
let metaPairs = jsonMetaToPairs meta
|
||||
let bl = case d of
|
||||
BinaryData bs -> BL.fromStrict bs
|
||||
TextualData t -> BL.fromStrict $ UTF8.fromText t
|
||||
JsonData v -> encode v
|
||||
let bs = case d of
|
||||
BinaryData bs' -> bs'
|
||||
TextualData t -> UTF8.fromText t
|
||||
JsonData v -> BL.toStrict $ encode v
|
||||
-- SHA1 hash for filename
|
||||
let fname = T.pack (showDigest (sha1 bl)) <>
|
||||
let fname = T.pack (show (hashWith SHA1 bs)) <>
|
||||
case extensionFromMimeType mt of
|
||||
Nothing -> ""
|
||||
Just ext -> "." <> ext
|
||||
insertMedia (T.unpack fname) (Just mt) bl
|
||||
insertMedia (T.unpack fname) (Just mt) (BL.fromStrict bs)
|
||||
return $ B.para $ B.imageWith ("",[],metaPairs) fname "" mempty
|
||||
|
||||
dataBlock ("text/html", TextualData t)
|
||||
|
||||
@@ -19,6 +19,7 @@ import qualified Data.IntMap as IntMap
|
||||
import qualified Data.Sequence as Seq
|
||||
import Control.Monad
|
||||
import Control.Monad.Except (throwError)
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import Data.List (find, foldl')
|
||||
import Data.Word (Word8, Word16)
|
||||
import Data.Default
|
||||
@@ -35,7 +36,6 @@ import Text.Pandoc.Logging (LogMessage(UnsupportedCodePage))
|
||||
import Text.Pandoc.Shared (tshow)
|
||||
import Data.Char (isAlphaNum, chr, isAscii, isLetter, isSpace, ord)
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
import Data.Digest.Pure.SHA (sha1, showDigest)
|
||||
import Data.Maybe (mapMaybe, fromMaybe)
|
||||
import Safe (lastMay, initSafe, headDef)
|
||||
-- import Debug.Trace
|
||||
@@ -920,7 +920,7 @@ handlePict toks = do
|
||||
Nothing -> (Nothing, "")
|
||||
case mimetype of
|
||||
Just mt -> do
|
||||
let pictname = showDigest (sha1 bytes) <> ext
|
||||
let pictname = show (hashWith SHA1 $ BL.toStrict bytes) <> ext
|
||||
insertMedia pictname (Just mt) bytes
|
||||
modifyGroup $ \g -> g{ gImage = Just pict{ picName = T.pack pictname,
|
||||
picBytes = bytes } }
|
||||
|
||||
@@ -24,7 +24,7 @@ import qualified Data.ByteString.Char8 as B
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.Text as T
|
||||
import Data.Char (isAlphaNum, isAscii)
|
||||
import Data.Digest.Pure.SHA (sha1, showDigest)
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import Network.URI (escapeURIString)
|
||||
import System.FilePath (takeDirectory, takeExtension, (</>))
|
||||
import Text.HTML.TagSoup
|
||||
@@ -216,8 +216,7 @@ convertTags (t@(TagOpen tagname as):ts)
|
||||
Fetched ("image/svg+xml", bs) | inlineSvgs -> do
|
||||
-- we filter CR in the hash to ensure that Windows
|
||||
-- and non-Windows tests agree:
|
||||
let hash = T.pack $ take 20 $ showDigest $
|
||||
sha1 $ L.fromStrict
|
||||
let hash = T.pack $ take 20 $ show $ hashWith SHA1
|
||||
$ B.filter (/='\r') bs
|
||||
return $ Left (hash, getSvgTags (toText bs))
|
||||
Fetched (mt,bs) -> return $ Right (x, makeDataURI (mt,bs))
|
||||
|
||||
@@ -23,6 +23,7 @@ module Text.Pandoc.Writers.Docx.OpenXML ( writeOpenXML, maxListLevel ) where
|
||||
import Control.Monad (when, unless)
|
||||
import Control.Applicative ((<|>))
|
||||
import Control.Monad.Except (catchError)
|
||||
import Crypto.Hash (hashWith, SHA1(SHA1))
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
import Data.Char (isLetter, isSpace)
|
||||
import Text.Pandoc.Char (isCJK)
|
||||
@@ -35,8 +36,6 @@ import Control.Monad.Reader ( asks, MonadReader(local) )
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Lazy as TL
|
||||
import Data.Digest.Pure.SHA (sha1, showDigest)
|
||||
import Skylighting
|
||||
import Text.DocLayout (hcat, vcat, literal, render)
|
||||
import Text.Pandoc.Class (PandocMonad, report, getMediaBag)
|
||||
@@ -45,7 +44,7 @@ import Text.Pandoc.MediaBag (lookupMedia, MediaItem(..))
|
||||
import qualified Text.Pandoc.Translations as Term
|
||||
import qualified Text.Pandoc.Class.PandocMonad as P
|
||||
import qualified Text.Pandoc.Builder as B
|
||||
import Text.Pandoc.UTF8 (fromTextLazy)
|
||||
import Text.Pandoc.UTF8 (fromText)
|
||||
import Text.Pandoc.Definition
|
||||
import Text.Pandoc.Highlighting (highlight)
|
||||
import Text.Pandoc.Templates (compileDefaultTemplate, renderTemplate)
|
||||
@@ -1082,7 +1081,7 @@ toBookmarkName s
|
||||
| Just (c, _) <- T.uncons s
|
||||
, isLetter c
|
||||
, T.length s <= 40 = s
|
||||
| otherwise = T.pack $ 'X' : drop 1 (showDigest (sha1 (fromTextLazy $ TL.fromStrict s)))
|
||||
| otherwise = T.pack $ 'X' : drop 1 (show (hashWith SHA1 (fromText s)))
|
||||
|
||||
maxListLevel :: Int
|
||||
maxListLevel = 8
|
||||
|
||||
Reference in New Issue
Block a user