From f60ac335e4e827fd242ab22539adb49f26e2c319 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Aug 2016 14:28:33 -0400 Subject: add progress bars to restore also, restore actually works! --- Types/Cost.hs | 13 +++++++++++++ Types/UI.hs | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Types') diff --git a/Types/Cost.hs b/Types/Cost.hs index 2f181a2..2aa6ee7 100644 --- a/Types/Cost.hs +++ b/Types/Cost.hs @@ -34,11 +34,24 @@ instance Monoid (Cost t) where mapCost :: (Integer -> Integer) -> Cost op -> Cost op mapCost f (CPUCost (Seconds n)) = CPUCost (Seconds (f n)) +showCostMinutes :: Cost op -> String +showCostMinutes (CPUCost (Seconds n)) + | n < 61 = "1 minute" + | otherwise = show (n `div` 60) ++ " minutes" + -- | Operations whose cost can be measured. data DecryptionOp data CreationOp data BruteForceOp +-- | Things that track their creation cost. +class HasCreationCost t where + getCreationCost :: t -> Cost CreationOp + +-- | Things that track their decryption cost. +class HasDecryptionCost t where + getDecryptionCost :: t -> Cost DecryptionOp + -- | Calculation of a cost that depends on some amount of entropy. type CostCalc op t = Entropy t -> Cost op diff --git a/Types/UI.hs b/Types/UI.hs index 0a0c789..7508293 100644 --- a/Types/UI.hs +++ b/Types/UI.hs @@ -3,6 +3,8 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE RankNTypes #-} + module Types.UI where import Types @@ -14,7 +16,7 @@ data UI = UI , promptName :: Title -> Desc -> Name -> (Name -> Maybe Problem) -> IO (Maybe Name) , promptPassword :: Bool -> Title -> Desc -> IO (Maybe Password) , promptKeyId :: Title -> Desc -> [(Name, KeyId)] -> IO (Maybe KeyId) - , withProgress :: Title -> Desc -> ((Percent -> IO ()) -> IO ()) -> IO () + , withProgress :: forall a. Title -> Desc -> ((Percent -> IO ()) -> IO a) -> IO a } type Title = String -- cgit v1.2.3