{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE OverloadedStrings #-} module Serialization where import Types import Raaz.Core.Encode import qualified Data.ByteString as B 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 fromByteString b = case B.break (== sepChar) b of (t, n) | B.null n -> Nothing | otherwise -> Just $ KeyId (KeyType t) (B.drop 1 n) instance Encodable Name where toByteString (Name n) = n fromByteString = Just . Name sepChar :: Word8 sepChar = 32