summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kiki.hs2
-rw-r--r--lib/KeyRing.hs12
-rw-r--r--lib/Kiki.hs2
3 files changed, 10 insertions, 6 deletions
diff --git a/kiki.hs b/kiki.hs
index 1143e04..b8d5f14 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -359,7 +359,7 @@ show_cert keyspec wkgrip db = do
359#elif defined(VERSION_dataenc) 359#elif defined(VERSION_dataenc)
360 qqs = map (Base64.encode . L.unpack) ds 360 qqs = map (Base64.encode . L.unpack) ds
361#endif 361#endif
362 pems = map (writePEM "CERTIFICATE") qqs 362 pems = map (writePEM PemCertificate) qqs
363 forM_ pems putStrLn 363 forM_ pems putStrLn
364 _ -> void $ warn (keyspec ++ ": ambiguous") 364 _ -> void $ warn (keyspec ++ ": ambiguous")
365 365
diff --git a/lib/KeyRing.hs b/lib/KeyRing.hs
index 44c3dce..0637044 100644
--- a/lib/KeyRing.hs
+++ b/lib/KeyRing.hs
@@ -841,8 +841,12 @@ subkeysForExport subspec (KeyData key _ _ subkeys) = do
841 sigtrusts 841 sigtrusts
842 in fmap fst v==Just True 842 in fmap fst v==Just True
843 843
844writePEM :: String -> String -> String 844data PemType = PemPublicKey | PemPrivateKey | PemCertificate
845writePEM typ dta = pem 845pemTypeString PemPublicKey = "PUBLIC KEY"
846pemTypeString PemPrivateKey = "PRIVATE KEY"
847pemTypeString PemCertificate = "CERTIFICATE"
848writePEM :: PemType -> String -> String
849writePEM (pemTypeString -> typ) dta = pem
846 where 850 where
847 pem = unlines . concat $ 851 pem = unlines . concat $
848 [ ["-----BEGIN " <> typ <> "-----"] 852 [ ["-----BEGIN " <> typ <> "-----"]
@@ -898,7 +902,7 @@ pemFromPacket Sec packet =
898#elif defined(VERSION_dataenc) 902#elif defined(VERSION_dataenc)
899 dta = Base64.encode (L.unpack bs) 903 dta = Base64.encode (L.unpack bs)
900#endif 904#endif
901 output = writePEM "RSA PRIVATE KEY" dta 905 output = writePEM PemPrivateKey dta
902 Just output 906 Just output
903 algo -> Nothing 907 algo -> Nothing
904pemFromPacket Pub packet = 908pemFromPacket Pub packet =
@@ -912,7 +916,7 @@ pemFromPacket Pub packet =
912#elif defined(VERSION_dataenc) 916#elif defined(VERSION_dataenc)
913 dta = Base64.encode (L.unpack bs) 917 dta = Base64.encode (L.unpack bs)
914#endif 918#endif
915 output = writePEM "PUBLIC KEY" dta 919 output = writePEM PemPublicKey dta
916 Just output 920 Just output
917 algo -> Nothing 921 algo -> Nothing
918pemFromPacket AutoAccess p@(PublicKeyPacket {}) = pemFromPacket Pub p 922pemFromPacket AutoAccess p@(PublicKeyPacket {}) = pemFromPacket Pub p
diff --git a/lib/Kiki.hs b/lib/Kiki.hs
index 7bf0e3d..e67c805 100644
--- a/lib/Kiki.hs
+++ b/lib/Kiki.hs
@@ -591,7 +591,7 @@ pemFromPacket k = do
591 qq = Base64.encode (L.unpack der) 591 qq = Base64.encode (L.unpack der)
592#endif 592#endif
593 return $ 593 return $
594 writePEM "PUBLIC KEY" qq -- ("TODO "++show keyspec) 594 writePEM PemPublicKey qq -- ("TODO "++show keyspec)
595 595
596show_pem :: String -> String -> KeyDB -> IO () 596show_pem :: String -> String -> KeyDB -> IO ()
597show_pem keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db pemFromPacket 597show_pem keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db pemFromPacket