#if __GLASGOW_HASKELL__ >= 710
#endif
module Hackage.Security.Trusted (
module Hackage.Security.Trusted.TCB
, (<$$>)
, VerifyRole(..)
, verifyFileInfo
, trustedFileInfoEqual
) where
import Data.Function (on)
import Data.Time
import Hackage.Security.TUF
import Hackage.Security.Trusted.TCB hiding (DeclareTrusted)
import Hackage.Security.Util.IO
import Hackage.Security.Util.Path
(<$$>) :: StaticPtr (a -> b) -> Trusted a -> Trusted b
(<$$>) = trustApply . trustStatic
class VerifyRole a where
verifyRole :: Trusted Root
-> TargetPath
-> Maybe FileVersion
-> Maybe UTCTime
-> Signed a
-> Either VerificationError (SignaturesVerified a)
instance VerifyRole Root where
verifyRole = verifyRole' . (static (rootRolesRoot . rootRoles) <$$>)
instance VerifyRole Timestamp where
verifyRole = verifyRole' . (static (rootRolesTimestamp . rootRoles) <$$>)
instance VerifyRole Snapshot where
verifyRole = verifyRole' . (static (rootRolesSnapshot . rootRoles) <$$>)
instance VerifyRole Mirrors where
verifyRole = verifyRole' . (static (rootRolesMirrors . rootRoles) <$$>)
verifyFileInfo :: forall root. IsFileSystemRoot root
=> Path (Rooted root) -> Trusted FileInfo -> IO Bool
verifyFileInfo fp trustedInfo = lazyAndM [
verifyFileLength
, (knownFileInfoEqual info) <$> computeFileInfo fp
]
where
verifyFileLength :: IO Bool
verifyFileLength = (== fileInfoLength) <$> getFileLength
getFileLength :: IO FileLength
getFileLength = FileLength . fromInteger <$> getFileSize fp
info@FileInfo{..} = trusted trustedInfo
trustedFileInfoEqual :: Trusted FileInfo -> Trusted FileInfo -> Bool
trustedFileInfoEqual = knownFileInfoEqual `on` trusted
lazyAndM :: Monad m => [m Bool] -> m Bool
lazyAndM [] = return True
lazyAndM (m:ms) = do b <- m
case b of
False -> return False
True -> lazyAndM ms