1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-03-20 04:46:22 +09:00

Support for instance-scope keys when verifying HTTP signature

This commit is contained in:
fr33domlover 2019-02-06 02:48:23 +00:00
parent 400245cf34
commit 8166d5b5eb
5 changed files with 178 additions and 70 deletions
src/Data/Aeson

View file

@ -18,6 +18,7 @@ module Data.Aeson.Local
, toEither
, fromEither
, frg
, parseHttpsURI'
, parseHttpsURI
, renderURI
, (.=?)
@ -29,7 +30,6 @@ import Prelude
import Control.Applicative ((<|>))
import Data.Aeson
import Data.Aeson.Types (Parser)
import Data.Maybe (isJust)
import Data.Text (Text)
import Network.URI
@ -56,16 +56,22 @@ fromEither (Right y) = Right' y
frg :: Text
frg = "https://forgefed.angeley.es/ns#"
parseHttpsURI :: Text -> Parser URI
parseHttpsURI t =
parseHttpsURI' :: Text -> Either String URI
parseHttpsURI' t =
case parseURI $ T.unpack t of
Nothing -> fail "Invalid absolute URI"
Nothing -> Left "Invalid absolute URI"
Just u ->
if uriScheme u == "https:"
then if isJust $ uriAuthority u
then return u
else fail "URI has empty authority"
else fail "URI scheme isn't https"
then case uriAuthority u of
Just a ->
if uriUserInfo a == "" && uriPort a == ""
then Right u
else Left "URI has userinfo or port"
Nothing -> Left "URI has empty authority"
else Left "URI scheme isn't https"
parseHttpsURI :: Text -> Parser URI
parseHttpsURI = either fail return . parseHttpsURI'
renderURI :: URI -> String
renderURI u = uriToString id u ""