diff options
-rw-r--r-- | kiki.hs | 2 | ||||
-rw-r--r-- | lib/KeyRing.hs | 12 | ||||
-rw-r--r-- | lib/Kiki.hs | 2 |
3 files changed, 10 insertions, 6 deletions
@@ -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 | ||
844 | writePEM :: String -> String -> String | 844 | data PemType = PemPublicKey | PemPrivateKey | PemCertificate |
845 | writePEM typ dta = pem | 845 | pemTypeString PemPublicKey = "PUBLIC KEY" |
846 | pemTypeString PemPrivateKey = "PRIVATE KEY" | ||
847 | pemTypeString PemCertificate = "CERTIFICATE" | ||
848 | writePEM :: PemType -> String -> String | ||
849 | writePEM (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 |
904 | pemFromPacket Pub packet = | 908 | pemFromPacket 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 |
918 | pemFromPacket AutoAccess p@(PublicKeyPacket {}) = pemFromPacket Pub p | 922 | pemFromPacket 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 | ||
596 | show_pem :: String -> String -> KeyDB -> IO () | 596 | show_pem :: String -> String -> KeyDB -> IO () |
597 | show_pem keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db pemFromPacket | 597 | show_pem keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db pemFromPacket |