From f094b80c0a5d74a459bfc980d591cb95fd0ae253 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 25 Oct 2017 23:15:56 +0200 Subject: [PATCH] Improve documentation --- filepath-crypto/changes.md | 3 +++ filepath-crypto/filepath-crypto.cabal | 2 +- .../src/Data/Binary/SerializationLength/Class.hs | 3 +++ filepath-crypto/src/Data/Binary/SerializationLength/TH.hs | 6 ++++++ filepath-crypto/src/System/FilePath/Cryptographic.hs | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/filepath-crypto/changes.md b/filepath-crypto/changes.md index 5be7154..ccff5c1 100644 --- a/filepath-crypto/changes.md +++ b/filepath-crypto/changes.md @@ -1,3 +1,6 @@ +# 0.0.0.1 + - Improved documentation + # 0.0.0.0 First published version diff --git a/filepath-crypto/filepath-crypto.cabal b/filepath-crypto/filepath-crypto.cabal index c7a618e..9d18540 100644 --- a/filepath-crypto/filepath-crypto.cabal +++ b/filepath-crypto/filepath-crypto.cabal @@ -1,5 +1,5 @@ name: filepath-crypto -version: 0.0.0.0 +version: 0.0.0.1 synopsis: Reversable and secure encoding of object ids as filepaths license: BSD3 license-file: LICENSE diff --git a/filepath-crypto/src/Data/Binary/SerializationLength/Class.hs b/filepath-crypto/src/Data/Binary/SerializationLength/Class.hs index 65cb29f..f9d9fea 100644 --- a/filepath-crypto/src/Data/Binary/SerializationLength/Class.hs +++ b/filepath-crypto/src/Data/Binary/SerializationLength/Class.hs @@ -6,5 +6,8 @@ module Data.Binary.SerializationLength.Class import GHC.TypeLits +-- | The class of types for which the result of serialization with @Data.Binary@ +-- is known statically to be of a certain length class KnownNat (SerializationLength a) => HasFixedSerializationLength a where + -- | The 'SerializationLength' is given in bytes at type level type SerializationLength a :: Nat diff --git a/filepath-crypto/src/Data/Binary/SerializationLength/TH.hs b/filepath-crypto/src/Data/Binary/SerializationLength/TH.hs index 7d498f9..b151477 100644 --- a/filepath-crypto/src/Data/Binary/SerializationLength/TH.hs +++ b/filepath-crypto/src/Data/Binary/SerializationLength/TH.hs @@ -10,6 +10,12 @@ import Data.Binary.SerializationLength.Class hasFixedSerializationLength :: Name -> Integer -> DecsQ +-- | Shorthand for defining instances of 'HasFixedSerializationLength', morally: +-- +-- > hasFixedSerializationLength typeName byteN = [d| +-- > instance HasFixedSerializiationLength $(typeName) where +-- > type SerializationLength $(typeName) = $(byteN) +-- > |] hasFixedSerializationLength (return . ConT -> t) (return . LitT . NumTyLit -> i) = [d| instance HasFixedSerializationLength $(t) where diff --git a/filepath-crypto/src/System/FilePath/Cryptographic.hs b/filepath-crypto/src/System/FilePath/Cryptographic.hs index 8248d4c..2b855c5 100644 --- a/filepath-crypto/src/System/FilePath/Cryptographic.hs +++ b/filepath-crypto/src/System/FilePath/Cryptographic.hs @@ -60,11 +60,11 @@ import Data.Proxy import GHC.TypeLits --- | @serializedLength@ is given in bytes. type CryptoFileName (namespace :: Symbol) = CryptoID namespace (CI FilePath) paddedLength :: Integral a => a -> a +-- | Round up to nearest multiple of 'cipherBlockSize' paddedLength l = bs * ceiling (l % bs) where bs = fromIntegral cipherBlockSize