git.iko.soy/typeable/random-token
on c1b1893 help sign in
3 files changed+102−120
since splitsnapshots
unifiedsplit
LICENSE−2 random-token.cabal+100−107 src/Random/Token.hs+2−11
LICENSEdeleted−2
@@ -1,2 +0,0 @@
1−Copyright © 2020, Antorica LLC
2−All rights reserved
random-token.cabal+100−107
@@ -1,111 +1,104 @@
1−cabal-version: 2.4
2−name: random-token
3−version: 0.1.0.0
4−synopsis: Implementation of random token generation and parsing
5−author: typeable.io
6−maintainer: s9gf4ult@gmail.com
7−license-file: LICENSE
8−category: Web
9−build-type: Simple
1+name: random-token
2+version: 0.1.0.0
3+synopsis: Implementation of random token generation and parsing
4+-- description:
5+author: typeable.io
6+maintainer: s9gf4ult@gmail.com
7+copyright: 2020 Author name here
8+category: Web
9+build-type: Simple
10+cabal-version: >=1.10
1011
1112library
12− hs-source-dirs: src
13− ghc-options: -Wall
14− exposed-modules: Random.Token
15− build-depends:
16− , aeson
17− , base >=4.9 && <5
18− , base64-bytestring
19− , bytestring >=0.10
20− , deepseq
21− , http-api-data
22− , QuickCheck
23− , text
24−
25− if !(impl(ghcjs) || arch(javascript) || arch(wasm32))
26− build-depends:
27− , cryptonite
28− , postgresql-simple
29−
30− default-language: Haskell2010
31− default-extensions:
32− CPP
33− ConstraintKinds
34− DataKinds
35− DeriveFoldable
36− DeriveFunctor
37− DeriveGeneric
38− DeriveTraversable
39− DuplicateRecordFields
40− FlexibleContexts
41− FlexibleInstances
42− FunctionalDependencies
43− GADTs
44− GeneralizedNewtypeDeriving
45− LambdaCase
46− MultiParamTypeClasses
47− MultiWayIf
48− NumDecimals
49− OverloadedStrings
50− PolyKinds
51− QuasiQuotes
52− RankNTypes
53− RecordWildCards
54− RoleAnnotations
55− ScopedTypeVariables
56− StandaloneDeriving
57− TemplateHaskell
58− TupleSections
59− TypeApplications
60− TypeFamilies
61− TypeOperators
62− UndecidableInstances
63− ViewPatterns
13+ hs-source-dirs: src
14+ ghc-options: -Wall
15+ exposed-modules: Random.Token
16+ build-depends: base >= 4.7 && < 5
17+ , QuickCheck
18+ , aeson
19+ , base64-bytestring
20+ , bytestring
21+ , deepseq
22+ , http-api-data
23+ , text
24+ if !impl(ghcjs)
25+ build-depends: cryptonite
26+ , postgresql-simple
27+ default-language: Haskell2010
28+ default-extensions: CPP
29+ , ConstraintKinds
30+ , DataKinds
31+ , DeriveFoldable
32+ , DeriveFunctor
33+ , DeriveGeneric
34+ , DeriveTraversable
35+ , DuplicateRecordFields
36+ , FlexibleContexts
37+ , FlexibleInstances
38+ , FunctionalDependencies
39+ , GADTs
40+ , GeneralizedNewtypeDeriving
41+ , LambdaCase
42+ , MultiParamTypeClasses
43+ , MultiWayIf
44+ , NumDecimals
45+ , OverloadedStrings
46+ , PolyKinds
47+ , QuasiQuotes
48+ , RankNTypes
49+ , RecordWildCards
50+ , RoleAnnotations
51+ , ScopedTypeVariables
52+ , StandaloneDeriving
53+ , TemplateHaskell
54+ , TupleSections
55+ , TypeApplications
56+ , TypeFamilies
57+ , TypeOperators
58+ , UndecidableInstances
59+ , ViewPatterns
6460
6561test-suite spec
66− type: exitcode-stdio-1.0
67− hs-source-dirs: spec
68− main-is: Test.hs
69− other-modules: TokenSpec
70− default-language: Haskell2010
71− build-depends:
72− , base >=4.10 && <5
73− , hspec
74− , random-token
75−
76− build-tool-depends: hspec-discover:hspec-discover
77− ghc-options:
78− -Wall -threaded -rtsopts "-with-rtsopts=-N -A64m -qb0 -n4m -T -I1"
79−
80− ghc-prof-options: -fprof-auto
81− default-extensions:
82− ConstraintKinds
83− DataKinds
84− DeriveFoldable
85− DeriveFunctor
86− DeriveGeneric
87− DeriveTraversable
88− DuplicateRecordFields
89− FlexibleContexts
90− FlexibleInstances
91− FunctionalDependencies
92− GADTs
93− GeneralizedNewtypeDeriving
94− LambdaCase
95− MultiParamTypeClasses
96− MultiWayIf
97− NumDecimals
98− OverloadedStrings
99− PolyKinds
100− QuasiQuotes
101− RankNTypes
102− RecordWildCards
103− ScopedTypeVariables
104− StandaloneDeriving
105− TemplateHaskell
106− TupleSections
107− TypeApplications
108− TypeFamilies
109− TypeOperators
110− UndecidableInstances
111− ViewPatterns
62+ type: exitcode-stdio-1.0
63+ hs-source-dirs: spec
64+ main-is: Test.hs
65+ other-modules: TokenSpec
66+ default-language: Haskell2010
67+ build-depends: base >= 4.10 && <4.13
68+ , hspec
69+ , random-token
70+ ghc-options: -Wall
71+ -threaded
72+ -rtsopts
73+ "-with-rtsopts=-N -A64m -qb0 -n4m -T -I1"
74+ ghc-prof-options: -fprof-auto
75+ default-extensions: ConstraintKinds
76+ , DataKinds
77+ , DeriveFoldable
78+ , DeriveFunctor
79+ , DeriveGeneric
80+ , DeriveTraversable
81+ , DuplicateRecordFields
82+ , FlexibleContexts
83+ , FlexibleInstances
84+ , FunctionalDependencies
85+ , GADTs
86+ , GeneralizedNewtypeDeriving
87+ , LambdaCase
88+ , MultiParamTypeClasses
89+ , MultiWayIf
90+ , NumDecimals
91+ , OverloadedStrings
92+ , PolyKinds
93+ , QuasiQuotes
94+ , RankNTypes
95+ , RecordWildCards
96+ , ScopedTypeVariables
97+ , StandaloneDeriving
98+ , TemplateHaskell
99+ , TupleSections
100+ , TypeApplications
101+ , TypeFamilies
102+ , TypeOperators
103+ , UndecidableInstances
104+ , ViewPatterns
src/Random/Token.hs+2−11
@@ -1,12 +1,9 @@
1−{-# LANGUAGE CPP #-}
21module Random.Token
32 ( Token
43 , tokenToAscii
54 , tokenToText
65 , asciiToToken
76 , textToToken
8− , unsafeCoerceToken
9− , tokenWithContents
107#ifndef ghcjs_HOST_OS
118 , generateToken
129#endif
@@ -24,7 +21,6 @@ import Data.Typeable
2421import Test.QuickCheck.Arbitrary
2522import Web.HttpApiData
2623
27−
2824#ifndef ghcjs_HOST_OS
2925import Crypto.Random as R
3026import Database.PostgreSQL.Simple.FromField
@@ -35,6 +31,8 @@ import Database.PostgreSQL.Simple.ToField
3531newtype Token (a :: k) = Token ByteString
3632 deriving (Ord, Eq, Show, NFData)
3733
34+type role Token nominal
35+
3836instance Arbitrary (Token a) where
3937 arbitrary = fmap (Token . BS.pack) $ sequence $ L.replicate 16 arbitrary
4038
@@ -59,7 +57,6 @@ instance ToField (Token a) where
5957
6058generateToken :: (MonadRandom m) => m (Token a)
6159generateToken = Token <$> R.getRandomBytes 16
62−
6360#endif
6461
6562instance FromHttpApiData (Token a) where
@@ -79,9 +76,3 @@ asciiToToken bs = Token <$> B64.decode bs
7976
8077textToToken :: Text -> Either String (Token a)
8178textToToken = asciiToToken . T.encodeUtf8
82−
83−tokenWithContents :: Text -> Token a
84−tokenWithContents = Token . T.encodeUtf8
85−
86−unsafeCoerceToken :: Token a -> Token b
87−unsafeCoerceToken (Token a) = Token a