diff options
author | joe <joe@jerkface.net> | 2014-04-30 20:03:01 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-04-30 20:03:01 -0400 |
commit | 0a69db51f2551a83a693af36bce360aa43390f90 (patch) | |
tree | 0e65f397721c71562c246d24f210c765cf10c832 | |
parent | fadee78f3eded0c33d7f4ee5f6ecc31282c2df26 (diff) |
writeKeyToFile now operates on InputFile intead of FilePath
-rw-r--r-- | KeyRing.hs | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -879,6 +879,7 @@ writeStamped0 ctx (FileDesc fd) stamp dowrite bs = do | |||
879 | writeStamped0 ctx inp stamp dowrite bs = do | 879 | writeStamped0 ctx inp stamp dowrite bs = do |
880 | let fname = resolveInputFile ctx inp | 880 | let fname = resolveInputFile ctx inp |
881 | forM_ fname $ \fname -> do | 881 | forM_ fname $ \fname -> do |
882 | createDirectoryIfMissing True $ takeDirectory fname | ||
882 | dowrite (Right fname) bs | 883 | dowrite (Right fname) bs |
883 | setFileTimes fname stamp stamp | 884 | setFileTimes fname stamp stamp |
884 | 885 | ||
@@ -1556,7 +1557,7 @@ rsaPrivateKeyFromPacket _ = Nothing | |||
1556 | 1557 | ||
1557 | 1558 | ||
1558 | writeKeyToFile :: | 1559 | writeKeyToFile :: |
1559 | Bool -> String -> FilePath -> Packet -> IO [(FilePath, KikiReportAction)] | 1560 | Bool -> String -> InputFile -> Packet -> IO [(InputFile, KikiReportAction)] |
1560 | writeKeyToFile False "PEM" fname packet = | 1561 | writeKeyToFile False "PEM" fname packet = |
1561 | case key_algorithm packet of | 1562 | case key_algorithm packet of |
1562 | RSA -> do | 1563 | RSA -> do |
@@ -1568,12 +1569,11 @@ writeKeyToFile False "PEM" fname packet = | |||
1568 | dta = Base64.encode (L.unpack bs) | 1569 | dta = Base64.encode (L.unpack bs) |
1569 | output = writePEM "RSA PRIVATE KEY" dta | 1570 | output = writePEM "RSA PRIVATE KEY" dta |
1570 | stamp = toEnum . fromEnum $ timestamp packet | 1571 | stamp = toEnum . fromEnum $ timestamp packet |
1571 | createDirectoryIfMissing True (takeDirectory fname) | ||
1572 | handleIO_ (return [(fname, FailedFileWrite)]) $ do | 1572 | handleIO_ (return [(fname, FailedFileWrite)]) $ do |
1573 | saved_mask <- setFileCreationMask 0o077 | 1573 | saved_mask <- setFileCreationMask 0o077 |
1574 | -- Note: The key's timestamp is included in it's fingerprint. | 1574 | -- Note: The key's timestamp is included in it's fingerprint. |
1575 | -- Therefore, we should attempt to preserve it. | 1575 | -- Therefore, we should attempt to preserve it. |
1576 | writeStamped (InputFileContext "" "") (ArgFile fname) stamp output | 1576 | writeStamped (InputFileContext "" "") fname stamp output |
1577 | setFileCreationMask saved_mask | 1577 | setFileCreationMask saved_mask |
1578 | return [(fname, ExportedSubkey)] | 1578 | return [(fname, ExportedSubkey)] |
1579 | algo -> return [(fname, UnableToExport algo $ fingerprint packet)] | 1579 | algo -> return [(fname, UnableToExport algo $ fingerprint packet)] |
@@ -1587,12 +1587,13 @@ writePEMKeys doDecrypt db exports = do | |||
1587 | let ds' = map functorToEither ds | 1587 | let ds' = map functorToEither ds |
1588 | if null (lefts ds') | 1588 | if null (lefts ds') |
1589 | then do | 1589 | then do |
1590 | rs <- mapM (uncurry $ writeKeyToFile False "PEM") | 1590 | rs <- mapM (\(f,p) -> writeKeyToFile False "PEM" (ArgFile f) p) |
1591 | (rights ds') | 1591 | (rights ds') |
1592 | return $ KikiSuccess (concat rs) | 1592 | return $ KikiSuccess (map (first resolve) $ concat rs) |
1593 | else do | 1593 | else do |
1594 | return (head $ lefts ds') | 1594 | return (head $ lefts ds') |
1595 | where | 1595 | where |
1596 | resolve f = concat $ resolveInputFile (InputFileContext "" "") f | ||
1596 | decryptKeys (fname,subspec,[p],_) = do | 1597 | decryptKeys (fname,subspec,[p],_) = do |
1597 | pun <- doDecrypt p | 1598 | pun <- doDecrypt p |
1598 | try pun $ \pun -> do | 1599 | try pun $ \pun -> do |