diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-16 13:40:52 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-16 13:40:52 -0400 |
commit | c9c476ae7216b80932b80870a2cd06f9339306aa (patch) | |
tree | ad2255c1d331bb2f286d7786e65151ba987a8247 /Serialization.hs | |
parent | 3229b02f0aa6bb23e351d00ade1263851a2f1826 (diff) | |
download | keysafe-c9c476ae7216b80932b80870a2cd06f9339306aa.tar.gz |
improve options to select secret key to backup/restore
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 |