clean up read/show abuse

Avoid ever using read to parse a non-haskell formatted input string.

show :: Key is arguably still show abuse, but displaying Keys as filenames
is just too useful to give up.
This commit is contained in:
Joey Hess 2011-11-07 23:21:22 -04:00
parent fdf988be6d
commit b11a63a860
18 changed files with 75 additions and 98 deletions

View file

@ -7,17 +7,9 @@
module Types.Crypto where
import Data.String.Utils
-- XXX ideally, this would be a locked memory region
newtype Cipher = Cipher String
data EncryptedCipher = EncryptedCipher String KeyIds
newtype KeyIds = KeyIds [String]
instance Show KeyIds where
show (KeyIds ks) = join "," ks
instance Read KeyIds where
readsPrec _ s = [(KeyIds (split "," s), "")]

View file

@ -17,14 +17,4 @@ import Types.UUID
data TrustLevel = SemiTrusted | UnTrusted | Trusted
deriving Eq
instance Show TrustLevel where
show SemiTrusted = "?"
show UnTrusted = "0"
show Trusted = "1"
instance Read TrustLevel where
readsPrec _ "1" = [(Trusted, "")]
readsPrec _ "0" = [(UnTrusted, "")]
readsPrec _ _ = [(SemiTrusted, "")]
type TrustMap = M.Map UUID TrustLevel

View file

@ -9,13 +9,12 @@ module Types.UUID where
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
data UUID = NoUUID | UUID String
deriving (Eq, Ord)
deriving (Eq, Ord, Show)
instance Show UUID where
show (UUID u) = u
show NoUUID = ""
fromUUID :: UUID -> String
fromUUID (UUID u) = u
fromUUID NoUUID = ""
instance Read UUID where
readsPrec _ s
| null s = [(NoUUID, "")]
| otherwise = [(UUID s, "")]
toUUID :: String -> UUID
toUUID [] = NoUUID
toUUID s = UUID s