diff options
Diffstat (limited to 'Types')
-rw-r--r-- | Types/Key.hs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Types/Key.hs b/Types/Key.hs index 8c1828c7e..3642eca1c 100644 --- a/Types/Key.hs +++ b/Types/Key.hs @@ -1,6 +1,6 @@ {- git-annex Key data type - - - Copyright 2011-2014 Joey Hess <id@joeyh.name> + - Copyright 2011-2016 Joey Hess <id@joeyh.name> - - Licensed under the GNU GPL version 3 or higher. -} @@ -21,6 +21,8 @@ module Types.Key ( ) where import System.Posix.Types +import Data.Aeson +import qualified Data.Text as T import Common import Utility.QuickCheck @@ -120,6 +122,13 @@ file2key s _ -> return k addfield _ _ _ = Nothing +instance ToJSON Key where + toJSON = toJSON . key2file + +instance FromJSON Key where + parseJSON (String t) = maybe mempty pure $ file2key $ T.unpack t + parseJSON _ = mempty + instance Arbitrary Key where arbitrary = Key <$> (listOf1 $ elements $ ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "-_\r\n \t") |