diff options
Diffstat (limited to 'Serialization.hs')
-rw-r--r-- | Serialization.hs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/Serialization.hs b/Serialization.hs index 4d6a671..8177821 100644 --- a/Serialization.hs +++ b/Serialization.hs @@ -11,19 +11,26 @@ module Serialization where import Types import Raaz.Core.Encode import qualified Data.ByteString as B +import qualified Data.ByteString.UTF8 as BU8 import Data.Monoid import Data.Word --- | A KeyId is serialized in the form "keytype value". --- For example "gpg C910D9222512E3C7" -instance Encodable KeyId where - toByteString (KeyId (KeyType t) i) = - t <> B.singleton sepChar <> i +-- | A SecretKeySource is serialized in the form "keytype value". +-- For example "gpg C910D9222512E3C7", or "file path". +instance Encodable SecretKeySource where + toByteString (GpgKey (KeyId b)) = + "gpg" <> B.singleton sepChar <> b + toByteString (KeyFile f) = + "file" <> B.singleton sepChar <> BU8.fromString f fromByteString b = case B.break (== sepChar) b of - (t, n) - | B.null n -> Nothing - | otherwise -> Just $ - KeyId (KeyType t) (B.drop 1 n) + (t, rest) + | B.null rest -> Nothing + | otherwise -> + let i = B.drop 1 rest + in case t of + "gpg" -> Just $ GpgKey (KeyId i) + "file" -> Just $ KeyFile (BU8.toString i) + _ -> Nothing instance Encodable Name where toByteString (Name n) = n |