summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-11-04 01:57:54 -0500
committerjoe <joe@jerkface.net>2013-11-04 01:57:54 -0500
commit64a378768de5a827873b118d8edafeb77d0fa347 (patch)
tree5572a3f3c1c55888b21fc5b9212510434f0f19a3
parent2548662e2b9da85d62cc4b91eaacc94aae05b048 (diff)
Fail to output a public key if the specification is ambiguous.
-rw-r--r--kiki.hs21
1 files changed, 14 insertions, 7 deletions
diff --git a/kiki.hs b/kiki.hs
index ab5a694..c76a89a 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -1095,7 +1095,8 @@ main = do
1095 let (pre, wk:subs) = seek_key (KeyGrip grip) sec 1095 let (pre, wk:subs) = seek_key (KeyGrip grip) sec
1096 (xs,ys) = seek_key (KeyTag wk sub) subs 1096 (xs,ys) = seek_key (KeyTag wk sub) subs
1097 when (not (null ys)) $ do 1097 when (not (null ys)) $ do
1098 let k = head ys 1098 let (xs',ys') = seek_key (KeyTag wk sub) (tail ys)
1099 k = head ys
1099 rsa = fromJust $ rsaKeyFromPacket k 1100 rsa = fromJust $ rsaKeyFromPacket k
1100 der = encodeASN1 DER (toASN1 rsa []) 1101 der = encodeASN1 DER (toASN1 rsa [])
1101 qq = Base64.encode (L.unpack der) 1102 qq = Base64.encode (L.unpack der)
@@ -1106,10 +1107,13 @@ main = do
1106 putStrLn $ show rsa 1107 putStrLn $ show rsa
1107 putStrLn $ show der 1108 putStrLn $ show der
1108 -} 1109 -}
1109 putStr $ unlines (["-----BEGIN PUBLIC KEY-----"] 1110 if null ys'
1110 ++split64 qq 1111 then
1111 ++["-----END PUBLIC KEY-----"]) 1112 putStr $ unlines (["-----BEGIN PUBLIC KEY-----"]
1112 return () 1113 ++split64 qq
1114 ++["-----END PUBLIC KEY-----"])
1115 else
1116 error "Key specification is ambiguous."
1113 1117
1114 doCmd cmd@(Add {}) = do 1118 doCmd cmd@(Add {}) = do
1115 ( homedir -- e3ozbhvej4jvlu43.onion/gpg/gnupghome 1119 ( homedir -- e3ozbhvej4jvlu43.onion/gpg/gnupghome
@@ -1360,9 +1364,12 @@ seek_key (KeyGrip grip) sec = (pre, subs)
1360 pred p@(SecretKeyPacket {}) = matchpr grip p == grip 1364 pred p@(SecretKeyPacket {}) = matchpr grip p == grip
1361 pred _ = False 1365 pred _ = False
1362 1366
1363seek_key (KeyTag key tag) ps = if null bs || null qs 1367seek_key (KeyTag key tag) ps = if null bs
1364 then (ps,[]) 1368 then (ps,[])
1365 else (reverse (tail qs), head qs : reverse rs ++ bs) 1369 else if null qs
1370 then let (as',bs') = seek_key (KeyTag key tag) (tail bs)
1371 in (as ++ (head bs:as'), bs')
1372 else (reverse (tail qs), head qs : reverse rs ++ bs)
1366 where 1373 where
1367 (as,bs) = break (\p -> isSignaturePacket p 1374 (as,bs) = break (\p -> isSignaturePacket p
1368 && has_tag tag p 1375 && has_tag tag p