summaryrefslogtreecommitdiff
path: root/Key.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-03-15 21:34:13 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-03-15 21:34:13 -0400
commit9d49fe2c172b135a1a3735827df014b5f45d99a2 (patch)
tree32caea71926c1b05d9b1921a16f364f57fc3e62f /Key.hs
parent675ee89749ba2272d37b763078020b6e5f4cd380 (diff)
first pass at using new keys
It compiles. It sorta works. Several subcommands are FIXME marked and broken, because things that used to accept separate --backend and --key params need to be changed to accept just a --key that encodes all the key info, now that there is metadata in keys.
Diffstat (limited to 'Key.hs')
-rw-r--r--Key.hs45
1 files changed, 26 insertions, 19 deletions
diff --git a/Key.hs b/Key.hs
index c542b46ed..178f1ca69 100644
--- a/Key.hs
+++ b/Key.hs
@@ -5,20 +5,35 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-module Key where
+module Key (
+ Key(..),
+ stubKey,
+ readKey,
+
+ prop_idempotent_key_read_show
+) where
import Test.QuickCheck
import Utility
+import System.Posix.Types
-{- A Key has a unique name, is associated with a backend,
- - and may contain other metadata. -}
+{- A Key has a unique name, is associated with a key/value backend,
+ - and may contain other optional metadata. -}
data Key = Key {
keyName :: String,
- keyBackend :: String,
- keySize :: Maybe Int,
- keyMtime :: Maybe Int
+ keyBackendName :: String,
+ keySize :: Maybe Integer,
+ keyMtime :: Maybe EpochTime
} deriving (Eq, Ord)
+stubKey :: Key
+stubKey = Key {
+ keyName = "",
+ keyBackendName = "",
+ keySize = Nothing,
+ keyMtime = Nothing
+}
+
fieldSep :: Char
fieldSep = ','
@@ -26,7 +41,7 @@ fieldSep = ','
- The name field is always shown last, and is the only field
- allowed to contain the fieldSep. -}
instance Show Key where
- show Key { keyBackend = b, keySize = s, keyMtime = m, keyName = n } =
+ show Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } =
('b' : b) +++ ('s' ?: s) +++ ('m' ?: m) +++ ('n' : n)
where
"" +++ y = y
@@ -36,16 +51,9 @@ instance Show Key where
_ ?: _ = ""
readKey :: String -> Maybe Key
-readKey s = if key == stub then Nothing else key
+readKey s = if key == Just stubKey then Nothing else key
where
- key = findfields s stub
-
- stub = Just Key {
- keyName = "",
- keyBackend = "",
- keySize = Nothing,
- keyMtime = Nothing
- }
+ key = findfields s $ Just stubKey
findfields ('n':v) (Just k) = Just $ k { keyName = v }
findfields (c:v) (Just k) =
@@ -54,7 +62,7 @@ readKey s = if key == stub then Nothing else key
_ -> Nothing
findfields _ v = v
- addfield k 'b' v = Just k { keyBackend = v }
+ addfield k 'b' v = Just k { keyBackendName = v }
addfield k 's' v = Just k { keySize = readMaybe v }
addfield k 'm' v = Just k { keyMtime = readMaybe v }
addfield _ _ _ = Nothing
@@ -65,8 +73,7 @@ instance Arbitrary Key where
n <- arbitrary
b <- elements ['A'..'Z']
s <- arbitrary
- m <- arbitrary
- return $ Key { keyName = n, keyBackend = [b] , keySize = s, keyMtime = m }
+ return $ Key { keyName = n, keyBackendName = [b] , keySize = s }
prop_idempotent_key_read_show :: Key -> Bool
prop_idempotent_key_read_show k = Just k == (readKey $ show k)