forked from tel/oauthenticated
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
52 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ module Network.OAuth.Types.Params where | |
|
||
import Control.Applicative | ||
import Crypto.Random | ||
import Data.ByteArray.Encoding (Base(Base64), convertToBase) | ||
import qualified Data.ByteString as S | ||
import qualified Data.ByteString.Base64 as S64 | ||
import qualified Data.ByteString.Char8 as S8 | ||
import Data.Data | ||
import Data.Time | ||
|
@@ -178,20 +178,27 @@ emptyPin = OaPin { timestamp = Timestamp (UTCTime (ModifiedJulianDay 0) 0) | |
|
||
-- | Creates a new, unique, unpredictable 'OaPin'. This should be used quickly | ||
-- as dependent on the OAuth server settings it may expire. | ||
freshPin :: CPRG gen => gen -> IO (OaPin, gen) | ||
freshPin :: DRG gen => gen -> IO (OaPin, gen) | ||
freshPin gen = do | ||
t <- Timestamp <$> getCurrentTime | ||
return (OaPin { timestamp = t, nonce = n }, gen') | ||
where | ||
(n, gen') = withRandomBytes gen 8 S64.encode | ||
(n, gen') = withRandomBytes gen 8 (convertToBase Base64) | ||
|
||
-- | generate @len random bytes and mapped the bytes to the function @f. | ||
-- | ||
-- This is equivalent to use Control.Arrow 'first' with 'randomBytesGenerate' | ||
withRandomBytes :: DRG g => g -> Int -> (S.ByteString -> a) -> (a, g) | ||
withRandomBytes rng len f = (f bs, rng') | ||
where (bs, rng') = randomBytesGenerate len rng | ||
This comment has been minimized.
Sorry, something went wrong.
ibotty
Author
Owner
|
||
|
||
-- | Uses 'emptyPin' to create an empty set of params 'Oa'. | ||
emptyOa :: Cred ty -> Oa ty | ||
emptyOa creds = | ||
Oa { credentials = creds, workflow = Standard, pin = emptyPin } | ||
|
||
-- | Uses 'freshPin' to create a fresh, default set of params 'Oa'. | ||
freshOa :: CPRG gen => Cred ty -> gen -> IO (Oa ty, gen) | ||
freshOa :: DRG gen => Cred ty -> gen -> IO (Oa ty, gen) | ||
freshOa creds gen = do | ||
(pinx, gen') <- freshPin gen | ||
return (Oa { credentials = creds, workflow = Standard, pin = pinx }, gen') | ||
|
There is no(t yet, see issue haskell-crypto/cryptonite#15 a)
cprgFork
in cryptonite. So this creates a new rng to use.That's why that function, as well as
upgradeE
below, need the additionalMonadIO
constraint.