-authCredentialP :: Parser AuthCredential
-authCredentialP = allowEOF $!
- do string "Basic"
- many1 lws
- b64 <- many1
- $ satisfy (\ c -> (c >= 'a' && c <= 'z') ||
- (c >= 'A' && c <= 'Z') ||
- (c >= '0' && c <= '9') ||
- c == '+' ||
- c == '/' ||
- c == '=')
- let decoded = map (toEnum . fromEnum) (B64.decode b64)
- case break (== ':') decoded of
- (uid, ':' : password)
- -> return (BasicAuthCredential uid password)
- _ -> failP
+ asc ∷ C8.ByteString → Parser Ascii
+ asc bs = case A.fromByteString bs of
+ Just as → return as
+ Nothing → fail "Non-ascii character in auth credential"