Remove dependency on sandi

This commit is contained in:
Gregor Kleen 2020-08-17 17:35:23 +02:00
parent 1177964936
commit 5e9a7e4c3c
4 changed files with 24 additions and 4 deletions

View File

@ -18,6 +18,7 @@ default-extensions:
- FlexibleContexts
- ConstraintKinds
- PatternSynonyms
- TypeFamilyDependencies
ghc-options:
- -Wall

View File

@ -34,12 +34,12 @@ dependencies:
- cryptoids-class >=0.0.0 && <0.1
- cryptoids >=0.5 && <0.6
- filepath >=1.4.1 && <1.5
- sandi >=0.4.0 && <0.6
- case-insensitive >=1.2.0 && <1.3
- binary >=0.8.3 && <0.11
- bytestring >=0.10.8 && <0.11
- exceptions >=0.8.3 && <0.11
- template-haskell >=2.11.1 && <2.16
- base32 <0.3.0.0
library:
source-dirs: src

View File

@ -44,7 +44,7 @@ import Data.CryptoID.Class (HasCryptoID)
import qualified Data.CryptoID.Class as Class (HasCryptoID(..))
import System.FilePath (FilePath)
import qualified Codec.Binary.Base32 as Base32
import Data.ByteString.Base32
import Data.CaseInsensitive (CI)
import qualified Data.CaseInsensitive as CI
import Data.Binary
@ -90,7 +90,7 @@ encrypt = Poly.encrypt determineLength $ return . encode
unless (fromIntegral l == natVal (Proxy :: Proxy (SerializationLength a))) $
throwM $ CiphertextConversionFailed str
return . Just $ paddedLength l
encode str = CI.mk . dropWhileEnd (== '=') . ByteString.Char8.unpack $ Base32.encode str
encode str = CI.mk . ByteString.Char8.unpack $ encodeBase32Unpadded' str
-- | Decrypt an arbitrary serializable value
@ -104,7 +104,7 @@ decrypt :: forall a m namespace.
, MonadThrow m
, HasFixedSerializationLength a
) => CryptoIDKey -> CryptoFileName namespace -> m a
decrypt = Poly.decrypt $ (\str -> either (const . throwM $ CiphertextConversionFailed str) return $ Base32.decode str) . ByteString.Char8.pack . padding (natVal (Proxy :: Proxy (SerializationLength a))) . map toUpper . CI.original
decrypt = Poly.decrypt $ (\str -> either (const . throwM $ CiphertextConversionFailed str) return $ decodeBase32Unpadded str) . ByteString.Char8.pack . padding (natVal (Proxy :: Proxy (SerializationLength a))) . map toUpper . CI.original
where
padding l str = str ++ replicate (genericIndex paddingTable $ l' `mod` 5) '='
where

19
stack.yaml.lock Normal file
View File

@ -0,0 +1,19 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages:
- completed:
hackage: sandi-0.5@sha256:b278d072ca717706ea38f9bd646e023f7f2576a778fb43565b434f93638849aa,3010
pantry-tree:
size: 3455
sha256: 5ca7ce4bc22ab9d4427bb149b5e283ab9db43375df14f7131fdfd48775f36350
original:
hackage: sandi-0.5
snapshots:
- completed:
size: 498186
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/22.yaml
sha256: d4f07dc3d5658260c2fe34266ad7618f6c84d34decf559c9c786ac1cfccf4e7b
original: lts-13.22