removed 3 partial !! and got a much nicer implementation
Yay, monadic Either!
This commit is contained in:
parent
fc87291e58
commit
813b28aa49
1 changed files with 21 additions and 10 deletions
|
@ -95,16 +95,27 @@ sshTranscript opts input = do
|
||||||
{- Ensure that the ssh public key doesn't include any ssh options, like
|
{- Ensure that the ssh public key doesn't include any ssh options, like
|
||||||
- command=foo, or other weirdness -}
|
- command=foo, or other weirdness -}
|
||||||
validateSshPubKey :: SshPubKey -> IO ()
|
validateSshPubKey :: SshPubKey -> IO ()
|
||||||
validateSshPubKey pubkey = do
|
validateSshPubKey pubkey = either error return $ check $ words pubkey
|
||||||
let ws = words pubkey
|
where
|
||||||
when (length ws > 3 || length ws < 2) $
|
check [prefix, _key, comment] = do
|
||||||
error $ "wrong number of words in ssh public key " ++ pubkey
|
checkprefix prefix
|
||||||
let (ssh, keytype) = separate (== '-') (ws !! 0)
|
checkcomment comment
|
||||||
unless (ssh == "ssh" && all isAlphaNum keytype) $
|
check [prefix, _key] =
|
||||||
error $ "bad ssh public key prefix " ++ ws !! 0
|
checkprefix prefix
|
||||||
when (length ws == 3) $
|
check _ = err "wrong number of words in ssh public key"
|
||||||
unless (all (\c -> isAlphaNum c || c == '@') (ws !! 2)) $
|
|
||||||
error $ "bad comment in ssh public key " ++ pubkey
|
ok = Right ()
|
||||||
|
err msg = Left $ unwords [msg, pubkey]
|
||||||
|
|
||||||
|
checkprefix prefix
|
||||||
|
| ssh == "ssh" && all isAlphaNum keytype = ok
|
||||||
|
| otherwise = err "bad ssh public key prefix"
|
||||||
|
where
|
||||||
|
(ssh, keytype) = separate (== '-') prefix
|
||||||
|
|
||||||
|
checkcomment comment
|
||||||
|
| all (\c -> isAlphaNum c || c == '@') comment = ok
|
||||||
|
| otherwise = err "bad comment in ssh public key"
|
||||||
|
|
||||||
addAuthorizedKeys :: Bool -> SshPubKey -> IO Bool
|
addAuthorizedKeys :: Bool -> SshPubKey -> IO Bool
|
||||||
addAuthorizedKeys rsynconly pubkey = boolSystem "sh"
|
addAuthorizedKeys rsynconly pubkey = boolSystem "sh"
|
||||||
|
|
Loading…
Add table
Reference in a new issue