mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-28 09:04:50 +09:00
Add InstanceURI datatype
This commit is contained in:
parent
4053f2f2b4
commit
aefb2aaee7
2 changed files with 17 additions and 2 deletions
|
@ -18,6 +18,10 @@ module Network.FedURI
|
||||||
, parseFedURI
|
, parseFedURI
|
||||||
, toURI
|
, toURI
|
||||||
, renderFedURI
|
, renderFedURI
|
||||||
|
|
||||||
|
, InstanceURI (..)
|
||||||
|
, i2f
|
||||||
|
, f2i
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
@ -99,3 +103,14 @@ toURI (FedURI h p f) = URI
|
||||||
|
|
||||||
renderFedURI :: FedURI -> Text
|
renderFedURI :: FedURI -> Text
|
||||||
renderFedURI = T.pack . flip (uriToString id) "" . toURI
|
renderFedURI = T.pack . flip (uriToString id) "" . toURI
|
||||||
|
|
||||||
|
newtype InstanceURI = InstanceURI
|
||||||
|
{ iuriHost :: Text
|
||||||
|
}
|
||||||
|
deriving Eq
|
||||||
|
|
||||||
|
i2f :: InstanceURI -> FedURI
|
||||||
|
i2f (InstanceURI h) = FedURI h "" ""
|
||||||
|
|
||||||
|
f2i :: FedURI -> InstanceURI
|
||||||
|
f2i = InstanceURI . furiHost
|
||||||
|
|
|
@ -435,7 +435,7 @@ fetchKey manager sigAlgo muActor uKey = runExceptT $ do
|
||||||
let fetch :: (MonadIO m, FromJSON a) => FedURI -> ExceptT String m a
|
let fetch :: (MonadIO m, FromJSON a) => FedURI -> ExceptT String m a
|
||||||
fetch u = ExceptT $ bimap displayException responseBody <$> httpGetAP manager u
|
fetch u = ExceptT $ bimap displayException responseBody <$> httpGetAP manager u
|
||||||
obj <- fetch uKey
|
obj <- fetch uKey
|
||||||
let inztance = uKey { furiPath = "", furiFragment = "" }
|
let inztance = f2i uKey
|
||||||
(actor, pkey) <-
|
(actor, pkey) <-
|
||||||
case obj of
|
case obj of
|
||||||
Left' pkey -> do
|
Left' pkey -> do
|
||||||
|
@ -481,7 +481,7 @@ fetchKey manager sigAlgo muActor uKey = runExceptT $ do
|
||||||
else return (actor, pk)
|
else return (actor, pk)
|
||||||
ExceptT . pure $ do
|
ExceptT . pure $ do
|
||||||
if publicKeyShared pkey
|
if publicKeyShared pkey
|
||||||
then if publicKeyOwner pkey == inztance
|
then if publicKeyOwner pkey == i2f inztance
|
||||||
then Right ()
|
then Right ()
|
||||||
else Left "Key is shared but its owner isn't the top-level instance URI"
|
else Left "Key is shared but its owner isn't the top-level instance URI"
|
||||||
else if publicKeyOwner pkey == actorId actor
|
else if publicKeyOwner pkey == actorId actor
|
||||||
|
|
Loading…
Reference in a new issue