summaryrefslogtreecommitdiffhomepage
path: root/Serialization.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-11 15:52:50 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-11 15:52:50 -0400
commit5decbad3eb779b1bbe11245cbde84701909e9c68 (patch)
tree79e28c04d76ee8e225ee344b9d8c07a922728002 /Serialization.hs
parent90b7c385f4e2f293502f9aca38aaa041b7b2f486 (diff)
downloadkeysafe-5decbad3eb779b1bbe11245cbde84701909e9c68.tar.gz
nearly able to generate shards now
Diffstat (limited to 'Serialization.hs')
-rw-r--r--Serialization.hs37
1 files changed, 9 insertions, 28 deletions
diff --git a/Serialization.hs b/Serialization.hs
index 6a283ff..224d67a 100644
--- a/Serialization.hs
+++ b/Serialization.hs
@@ -6,42 +6,23 @@ module Serialization where
import Types
import Raaz.Core.Encode
import qualified Data.ByteString as B
-import qualified Data.ByteString.Char8 as B8
import Data.Monoid
import Data.Word
-import Text.Read
--- TODO
--- | An EncryptedSecretKey is serialized as first a md5sum of the rest
--- of the content, and then a SelfDescription EncryptedSecretKey,
--- and finally the
---instance Encodable EncryptedSecretKey where
--- toByteString (EncryptedSecretKey b _) = b
--- fromByteString b =
-
--- | A KeyIdent is serialized in the form "keytype name".
--- For example "gpg Joey Hess"
-instance Encodable KeyIdent where
- toByteString (KeyIdent (KeyType t) (Name n)) =
- t <> B.singleton sepChar <> n
+-- | 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
fromByteString b = case B.break (== sepChar) b of
(t, n)
| B.null n -> Nothing
| otherwise -> Just $
- KeyIdent (KeyType t) (Name (B.drop 1 n))
+ KeyId (KeyType t) (B.drop 1 n)
--- | An ObjectIdent is serialied in the form "shardnum keytype name"
--- For example "1 gpg Joey Hess"
-instance Encodable ObjectIdent where
- toByteString (ObjectIdent (ShardNum n) keyident) =
- B8.pack (show n) <> B.singleton sepChar <> toByteString keyident
- fromByteString b = case B.break (== sepChar) b of
- (ns, rest)
- | B.null ns -> Nothing
- | otherwise -> do
- keyident <- fromByteString (B.drop 1 rest)
- n <- readMaybe (B8.unpack ns)
- return $ ObjectIdent (ShardNum n) keyident
+instance Encodable Name where
+ toByteString (Name n) = n
+ fromByteString = Just . Name
sepChar :: Word8
sepChar = 32