summaryrefslogtreecommitdiff
path: root/kiki.hs
diff options
context:
space:
mode:
Diffstat (limited to 'kiki.hs')
-rw-r--r--kiki.hs67
1 files changed, 0 insertions, 67 deletions
diff --git a/kiki.hs b/kiki.hs
index 1c6fa37..43d170c 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -650,19 +650,6 @@ getPassphrase cmd =
650 650
651#define HOMEOPTION (def &= explicit &= name "homedir" &= typDir ) 651#define HOMEOPTION (def &= explicit &= name "homedir" &= typDir )
652 652
653flattenKeys :: Bool -> KeyDB -> Message
654flattenKeys isPublic db = Message $ concatMap (map packet . flattenTop "" isPublic . snd) (prefilter . Map.assocs $ db)
655 where
656 prefilter = if isPublic then id else filter isSecret
657 where
658 isSecret (_,(KeyData
659 (MappedPacket { packet=(SecretKeyPacket {})})
660 _
661 _
662 _)) = True
663 isSecret _ = False
664
665
666writeOutKeyrings :: Map.Map FilePath t -> KeyDB -> IO () 653writeOutKeyrings :: Map.Map FilePath t -> KeyDB -> IO ()
667writeOutKeyrings lkmap db = do 654writeOutKeyrings lkmap db = do
668 let ks = Map.elems db 655 let ks = Map.elems db
@@ -1704,60 +1691,6 @@ isTopKey p@(SecretKeyPacket {}) | not (is_subkey p) = True
1704isTopKey p@(PublicKeyPacket {}) | not (is_subkey p) = True 1691isTopKey p@(PublicKeyPacket {}) | not (is_subkey p) = True
1705isTopKey _ = False 1692isTopKey _ = False
1706 1693
1707selectSecretKey :: (KeySpec,Maybe String) -> KeyDB -> Maybe Packet
1708selectSecretKey (spec,mtag) db = selectKey0 False (spec,mtag) db
1709
1710selectPublicKey :: (KeySpec,Maybe String) -> KeyDB -> Maybe Packet
1711selectPublicKey (spec,mtag) db = selectKey0 True (spec,mtag) db
1712
1713selectKey0 :: Bool -> (KeySpec,Maybe String) -> KeyDB -> Maybe Packet
1714selectKey0 wantPublic (spec,mtag) db = do
1715 let Message ps = flattenKeys wantPublic db
1716 ys = snd $ seek_key spec ps
1717 flip (maybe (listToMaybe ys)) mtag $ \tag -> do
1718 let (subspec,ys1) = (KeyTag y tag,ys1) where y:ys1 = ys
1719 zs = snd $ seek_key subspec ys1
1720 listToMaybe zs
1721
1722seek_key :: KeySpec -> [Packet] -> ([Packet],[Packet])
1723seek_key (KeyGrip grip) sec = (pre, subs)
1724 where
1725 (pre,subs) = break pred sec
1726 pred p@(SecretKeyPacket {}) = matchpr grip p == grip
1727 pred p@(PublicKeyPacket {}) = matchpr grip p == grip
1728 pred _ = False
1729
1730seek_key (KeyTag key tag) ps = if null bs
1731 then (ps,[])
1732 else if null qs
1733 then let (as',bs') = seek_key (KeyTag key tag) (tail bs)
1734 in (as ++ (head bs:as'), bs')
1735 else (reverse (tail qs), head qs : reverse rs ++ bs)
1736 where
1737 (as,bs) = break (\p -> isSignaturePacket p
1738 && has_tag tag p
1739 && isJust (signature_issuer p)
1740 && matchpr (fromJust $ signature_issuer p) key == fromJust (signature_issuer p) )
1741 ps
1742 (rs,qs) = break isKey (reverse as)
1743
1744 has_tag tag p = tag `elem` mapMaybe usage (hashed_subpackets p)
1745 || tag `elem` map usageString (mapMaybe keyflags (hashed_subpackets p))
1746
1747seek_key (KeyUidMatch pat) ps = if null bs
1748 then (ps,[])
1749 else if null qs
1750 then let (as',bs') = seek_key (KeyUidMatch pat) (tail bs)
1751 in (as ++ (head bs:as'), bs')
1752 else (reverse (tail qs), head qs : reverse rs ++ bs)
1753 where
1754 (as,bs) = break (isInfixOf pat . uidStr)
1755 ps
1756 (rs,qs) = break isKey (reverse as)
1757
1758 uidStr (UserIDPacket s) = s
1759 uidStr _ = ""
1760
1761groupTops ps = groupBy (\_ b -> not (isTopKey b)) ps 1694groupTops ps = groupBy (\_ b -> not (isTopKey b)) ps
1762 1695
1763 1696