zohl / servant-auth-cookie

Authentication via encrypted cookies
BSD 3-Clause "New" or "Revised" License
23 stars 23 forks source link

Compile failure w/ pre-AMP base #29

Open hvr opened 7 years ago

hvr commented 7 years ago

Compiling with base-4.7 fails w/ the latest release (see also http://104.239.175.197:8080/package/servant-auth-cookie):

Configuring component lib from servant-auth-cookie-0.5.0...
Preprocessing library servant-auth-cookie-0.5.0...
[1 of 1] Compiling Servant.Server.Experimental.Auth.Cookie ( src/Servant/Server/Experimental/Auth/Cookie.hs, /tmp/matrix-worker/1492269924/dist-newstyle/build/x86_64-linux/ghc-7.8.4/servant-auth-cookie-0.5.0/build/Servant/Server/Experimental/Auth/Cookie.o )

src/Servant/Server/Experimental/Auth/Cookie.hs:469:18:
    Could not deduce (Functor m) arising from a use of ‘<$>’
    from the context (MonadIO m, MonadThrow m, ServerKeySet k)
      bound by the type signature for
                 decryptCookie :: (MonadIO m, MonadThrow m, ServerKeySet k) =>
                                  AuthCookieSettings
                                  -> k
                                  -> Tagged EncryptedCookie ByteString
                                  -> m (WithMetadata Cookie)
      at src/Servant/Server/Experimental/Auth/Cookie.hs:(448,18)-(452,28)
    or from (HashAlgorithm h, BlockCipher c)
      bound by a pattern with constructor
                 AuthCookieSettings :: forall h c.
                                       (HashAlgorithm h, BlockCipher c) =>
                                       ByteString
                                       -> [ByteString]
                                       -> NominalDiffTime
                                       -> String
                                       -> ByteString
                                       -> Proxy h
                                       -> Proxy c
                                       -> CipherAlgorithm c
                                       -> CipherAlgorithm c
                                       -> AuthCookieSettings,
               in an equation for ‘decryptCookie’
      at src/Servant/Server/Experimental/Auth/Cookie.hs:453:15-37
    Possible fix:
      add (Functor m) to the context of
        the data constructor ‘AuthCookieSettings’
        or the type signature for
             decryptCookie :: (MonadIO m, MonadThrow m, ServerKeySet k) =>
                              AuthCookieSettings
                              -> k
                              -> Tagged EncryptedCookie ByteString
                              -> m (WithMetadata Cookie)
    In the expression:
      (, True)
      <$>
        maybe
          (throwM $ IncorrectMAC mac)
          (return)
          (listToMaybe . map fst . filter snd . map (id &&& checkMac)
           $ rotatedKeys)
    In a stmt of a 'do' block:
      (serverKey, renew) <- if checkMac currentKey then
                                return (currentKey, False)
                            else
                                (, True)
                                <$>
                                  maybe
                                    (throwM $ IncorrectMAC mac)
                                    (return)
                                    (listToMaybe . map fst . filter snd . map (id &&& checkMac)
                                     $ rotatedKeys)
    In the expression:
      do { currentTime <- liftIO getCurrentTime;
           let ivSize = blockSize (unProxy acsCipher)
               expSize
                 = length
                     (formatTime defaultTimeLocale acsExpirationFormat currentTime)
               ....;
           (currentKey, rotatedKeys) <- getKeys sks;
           (serverKey, renew) <- if checkMac currentKey then
                                     return (currentKey, False)
                                 else
                                     (, True)
                                     <$>
                                       maybe
                                         (throwM $ IncorrectMAC mac)
                                         (return)
                                         (listToMaybe . map fst . filter snd . map (id &&& checkMac)
                                          $ rotatedKeys);
           .... }

btw, I also notice that

flag build-examples
  description:        Build example executables.
  default:            False

should rather be declared to be a manual: True flag (so that the cabal solver doesn't consider it part of the variables it solves for).

zohl commented 7 years ago

Hello @hvr, thank you for pointing this out!

Looks like, I forgot, that Monad m doesn't imply Functor m in GHC 7.8 (and older). I've fixed this in v0.5.0.1 and marked v0.5.0 as deprecated.