From 6f780117751873f519df8a38b9ee8d1220f390c4 Mon Sep 17 00:00:00 2001 From: joe Date: Sat, 9 Nov 2013 20:37:42 -0500 Subject: Ability to specify top key by substring of user id. --- kiki.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index ccb2510..990e8e3 100644 --- a/kiki.hs +++ b/kiki.hs @@ -799,6 +799,7 @@ getPassphrase cmd = data KeySpec = KeyGrip String | KeyTag Packet String + | KeyUidMatch String is40digitHex xs = ys == xs && length ys==40 @@ -1301,10 +1302,12 @@ main = do _ | null top -> KeyGrip grip _ | toptyp=="fp" || (null toptyp && is40digitHex top) -> {- trace "using top" $ -} KeyGrip top - _ | otherwise -> todo + _ | toptyp=="u" -> KeyUidMatch top + _ | otherwise -> KeyUidMatch top (pre, wksubs) = seek_key topspec allpkts if null wksubs then error ("No match for "++spec) else do let wk:subs = wksubs + (_,wksubs') = seek_key topspec subs -- ambiguity check (_,ys) = case subtyp of "t" -> seek_key (KeyTag wk sub) subs "fp" | top=="" -> ([],wk:subs) @@ -1325,7 +1328,7 @@ main = do putStrLn $ show rsa putStrLn $ show der -} - if null ys' + if null ys' && null wksubs' then putStr $ unlines (["-----BEGIN PUBLIC KEY-----"] ++split64 qq @@ -1599,5 +1602,19 @@ seek_key (KeyTag key tag) ps = if null bs has_tag tag p = tag `elem` mapMaybe usage (hashed_subpackets p) || tag `elem` map usageString (mapMaybe keyflags (hashed_subpackets p)) + +seek_key (KeyUidMatch pat) ps = if null bs + then (ps,[]) + else if null qs + then let (as',bs') = seek_key (KeyUidMatch pat) (tail bs) + in (as ++ (head bs:as'), bs') + else (reverse (tail qs), head qs : reverse rs ++ bs) + where + (as,bs) = break (isInfixOf pat . uidStr) + ps + (rs,qs) = break isKey (reverse as) + + uidStr (UserIDPacket s) = s + uidStr _ = "" groupTops ps = groupBy (\_ b -> not (isTopKey b)) ps -- cgit v1.2.3