Switch to hpack & get rid of encoding

This commit is contained in:
Gregor Kleen 2018-01-15 14:44:02 +01:00
parent b6397f2348
commit d5ad5ff785
15 changed files with 196 additions and 157 deletions

4
.gitignore vendored
View File

@ -3,7 +3,11 @@
**/.stack-work
**/dist
cryptoids/cryptoids.cabal
cryptoids/cryptoids.nix
cryptoids-types/cryptoids-types.cabal
cryptoids-types/cryptoids-types.nix
filepath-crypto/filepath-crypto.cabal
filepath-crypto/filepath-crypto.nix
uuid-crypto/uuid-crypto.cabal
uuid-crypto/uuid-crypto.nix

View File

@ -1,30 +0,0 @@
name: cryptoids-types
synopsis: Shared types for encrypting internal object identifiers before exposure
version: 0.0.0
license: BSD3
license-file: LICENSE
author: Gregor Kleen
maintainer: aethoago@141.li
category: Web
build-type: Simple
cabal-version: >=1.10
extra-source-files: changes.md
source-repository head
type: git
location: https://git.rheperire.org/cryptoids
subdir: cryptoids-types
library
exposed-modules: Data.CryptoID
default-extensions: KindSignatures
, DataKinds
, GeneralizedNewtypeDeriving
, DeriveGeneric
, DeriveDataTypeable
build-depends: base >=4.9 && <4.11
, binary >=0.8.3.0 && <0.9
, path-pieces >=0.2.1 && <0.3
, http-api-data >=0.3.7.1 && <0.4
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall -fno-warn-name-shadowing

View File

@ -0,0 +1,33 @@
name: cryptoids-types
synopsis: Shared types for encrypting internal object identifiers before exposure
version: 0.0.0
license: BSD3
license-file: LICENSE
author: Gregor Kleen <aethoago@141.li>
maintainer: Gregor Kleen <aethoago@141.li>
category: Web
extra-doc-files:
- changes.md
git: https://git.rheperire.org/cryptoids/cryptoids-types
default-extensions:
- KindSignatures
- DataKinds
- GeneralizedNewtypeDeriving
- DeriveGeneric
- DeriveDataTypeable
ghc-options:
- -Wall
- -fno-warn-name-shadowing
dependencies:
- base
- binary
- path-pieces
- http-api-data
library:
source-dirs: src
exposed-modules:
- Data.CryptoID

View File

@ -1,37 +0,0 @@
name: cryptoids
version: 0.4.0.0
synopsis: Reversable and secure encoding of object ids as a bytestring
license: BSD3
license-file: LICENSE
author: Gregor Kleen
maintainer: aethoago@141.li
category: cryptography
build-type: Simple
cabal-version: >=1.10
extra-source-files: changes.md
source-repository head
type: git
location: https://git.rheperire.org/cryptoids
subdir: cryptoids
library
exposed-modules: Data.CryptoID.Poly
, Data.CryptoID.ByteString
default-extensions: RankNTypes
, DataKinds
, GeneralizedNewtypeDeriving
, ViewPatterns
, RecordWildCards
, FlexibleContexts
build-depends: base >=4.9.1.0 && <4.11
, cryptoids-types ==0.0.0
, cryptonite >=0.23 && <0.25
, bytestring >=0.10.8.1 && <0.11
, binary >=0.8.3.0 && <0.9
, memory >=0.14.6 && <0.15
, exceptions >=0.8.3 && <0.9
, filepath >=1.4.1.1 && <1.5
, directory >=1.3.0.0 && <1.4
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall -fno-warn-name-shadowing

37
cryptoids/package.yaml Normal file
View File

@ -0,0 +1,37 @@
name: cryptoids
version: 0.4.0.0
synopsis: Reversable and secure encoding of object ids as a bytestring
category: cryptography
author: Gregor Kleen <aethoago@141.li>
maintainer: Gregor Kleen <aethoago@141.li>
license: BSD3
git: https://git.rheperire.org/cryptoids/cryptoids
extra-doc-files:
- changes.md
default-extensions:
- RankNTypes
- DataKinds
- GeneralizedNewtypeDeriving
- ViewPatterns
- RecordWildCards
- FlexibleContexts
ghc-options:
- -Wall
- -fno-warn-name-shadowing
dependencies:
- base
- cryptoids-types
- cryptonite
- bytestring
- binary
- memory
- exceptions
- filepath
- directory
library:
source-dirs: src
exposed-modules:
- Data.CryptoID.Poly
- Data.CryptoID.ByteString

View File

@ -1,3 +1,6 @@
# 0.0.0.3
- Got rid of `encoding`
# 0.0.0.2
- Improved documentation

View File

@ -1,45 +0,0 @@
name: filepath-crypto
version: 0.0.0.2
synopsis: Reversable and secure encoding of object ids as filepaths
license: BSD3
license-file: LICENSE
author: Gregor Kleen
maintainer: aethoago@141.li
category: cryptography
build-type: Simple
cabal-version: >=1.10
extra-source-files: changes.md
source-repository head
type: git
location: https://git.rheperire.org/cryptoids
subdir: filepath-crypto
library
exposed-modules: System.FilePath.Cryptographic
, Data.Binary.SerializationLength
, Data.Binary.SerializationLength.TH
other-modules: Data.Binary.SerializationLength.Class
default-extensions: KindSignatures
, ViewPatterns
, FlexibleContexts
, GeneralizedNewtypeDeriving
, PatternGuards
, RecordWildCards
, DataKinds
, DeriveDataTypeable
, DeriveGeneric
other-extensions: ScopedTypeVariables
build-depends: base >=4.9 && <4.11
, cryptoids-types ==0.0.0
, cryptoids ==0.4.0.*
, filepath >=1.4.1.1 && <1.5
, sandi >=0.4.1 && <0.5
, case-insensitive >=1.2.0.10 && <1.3
, binary >=0.8.3.0 && <0.9
, bytestring >=0.10.8.1 && <0.11
, exceptions >=0.8.3 && <0.9
, encoding >=0.8.2 && <0.9
, template-haskell >=2.11.0.0 && <2.13
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall -fno-warn-name-shadowing

View File

@ -0,0 +1,44 @@
name: filepath-crypto
version: 0.0.0.3
synopsis: Reversable and secure encoding of object ids as filepaths
category: cryptography
author: Gregor Kleen <aethoago@141.li>
maintainer: Gregor Kleen <aethoago@141.li>
license: BSD3
git: https://git.rheperire.org/cryptoids/filepath-crypto
extra-doc-files:
- changes.md
default-extensions:
- KindSignatures
- ViewPatterns
- FlexibleContexts
- GeneralizedNewtypeDeriving
- PatternGuards
- RecordWildCards
- DataKinds
- DeriveDataTypeable
- DeriveGeneric
other-extensions:
- ScopedTypeVariables
ghc-options:
- -Wall
- -fno-warn-name-shadowing
dependencies:
- base
- cryptoids-types
- cryptoids
- filepath
- sandi
- case-insensitive
- binary
- bytestring
- exceptions
- template-haskell
library:
source-dirs: src
exposed-modules:
- System.FilePath.Cryptographic
- Data.Binary.SerializationLength
- Data.Binary.SerializationLength.TH

View File

@ -47,14 +47,13 @@ import Data.CaseInsensitive (CI)
import qualified Data.CaseInsensitive as CI
import Data.Binary
import Data.Binary.SerializationLength
import Data.Encoding.UTF8
import Data.Encoding (decodeStrictByteString, encodeStrictByteString)
import Data.Char (toUpper)
import Data.Ratio ((%))
import Data.List
import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Char8 as ByteString.Char8
import Control.Monad
import Control.Monad.Catch
@ -88,7 +87,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 (== '=') . decodeStrictByteString UTF8 $ Base32.encode str
encode str = CI.mk . dropWhileEnd (== '=') . ByteString.Char8.unpack $ Base32.encode str
-- | Decrypt an arbitrary serializable value
@ -102,7 +101,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) . encodeStrictByteString UTF8 . padding (natVal (Proxy :: Proxy (SerializationLength a))) . map toUpper . CI.original
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
where
padding l str = str ++ replicate (genericIndex paddingTable $ l' `mod` 5) '='
where

View File

@ -1,2 +1,4 @@
cabal2nix.gup:
**/*.nix
**/*.nix
hpack.gup:
**/*.cabal

21
gup/cryptoids.nix.gup Executable file
View File

@ -0,0 +1,21 @@
#! /usr/bin/env nix-shell
#! nix-shell -i zsh -p zsh
exec 1>${1}
gup -u \
./cryptoids-types/cryptoids-types.nix \
./uuid-crypto/uuid-crypto.nix \
./filepath-crypto/filepath-crypto.nix \
./cryptoids/cryptoids.nix
<<EOF
{ callPackage }:
rec {
cryptoids-types = callPackage ./cryptoids-types/cryptoids-types.nix {};
uuid-crypto = callPackage ./uuid-crypto/uuid-crypto.nix {};
filepath-crypto = callPackage ./filepath-crypto/filepath-crypto.nix {};
cryptoids = callPackage ./cryptoids/cryptoids.nix { inherit cryptoids-types; };
}
EOF

8
gup/hpack.gup Executable file
View File

@ -0,0 +1,8 @@
#! /usr/bin/env nix-shell
#! nix-shell -i zsh -p zsh haskellPackages.hpack
gup -u ${2:h}/package.yaml
cd ${2:h}
hpack . - >${1}

View File

@ -15,7 +15,7 @@
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-9.9
resolver: lts-10.3
# User packages to be built.
# Various formats can be used as shown in the example below.
@ -44,7 +44,6 @@ packages:
# (e.g., acme-missiles-0.3)
extra-deps:
- regex-compat-0.93.1
- encoding-0.8.2
# Override default flag values for local packages and extra-deps
flags: {}

39
uuid-crypto/package.yaml Normal file
View File

@ -0,0 +1,39 @@
name: uuid-crypto
version: 1.3.1.0
synopsis: Reversable and secure encoding of object ids as uuids
category: cryptography
author: Gregor Kleen <aethoago@141.li>
maintainer: Gregor Kleen <aethoago@141.li>
license: BSD3
git: https://git.rheperire.org/cryptoids/uuid-crypto
extra-doc-files:
- changes.md
default-extensions:
- KindSignatures
- ViewPatterns
- FlexibleContexts
- GeneralizedNewtypeDeriving
- PatternGuards
- RecordWildCards
- DataKinds
- DeriveDataTypeable
- DeriveGeneric
other-extensions:
- ScopedTypeVariables
ghc-options:
- -Wall
- -fno-warn-name-shadowing
dependencies:
- base
- cryptoids-types
- cryptoids
- uuid
- binary
- bytestring
- exceptions
library:
source-dirs: src
exposed-modules:
- Data.UUID.Cryptographic

View File

@ -1,38 +0,0 @@
name: uuid-crypto
version: 1.3.1.0
synopsis: Reversable and secure encoding of object ids as uuids
license: BSD3
license-file: LICENSE
author: Gregor Kleen
maintainer: aethoago@141.li
category: cryptography
build-type: Simple
cabal-version: >=1.10
extra-source-files: changes.md
source-repository head
type: git
location: https://git.rheperire.org/cryptoids
subdir: uuid-crypto
library
exposed-modules: Data.UUID.Cryptographic
default-extensions: KindSignatures
, ViewPatterns
, FlexibleContexts
, GeneralizedNewtypeDeriving
, PatternGuards
, RecordWildCards
, DataKinds
, DeriveDataTypeable
, DeriveGeneric
other-extensions: ScopedTypeVariables
build-depends: base >=4.9 && <4.11
, cryptoids-types ==0.0.0
, cryptoids ==0.4.0.*
, uuid >=1.3.13 && <1.4
, binary >=0.8.3.0 && <0.9
, bytestring >=0.10.8.1 && <0.11
, exceptions >=0.8.3 && <0.9
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall -fno-warn-name-shadowing