module Crypto.WebAuthn.Metadata
( metadataBlobToRegistry,
Service.MetadataServiceRegistry,
)
where
import qualified Crypto.WebAuthn.Metadata.Service.Processing as Service
import qualified Crypto.WebAuthn.Metadata.Service.Types as Service
import qualified Data.ByteString as BS
import qualified Data.Hourglass as HG
import Data.Text (Text)
import qualified Data.Text as Text
metadataBlobToRegistry ::
BS.ByteString ->
HG.DateTime ->
Either Text Service.MetadataServiceRegistry
metadataBlobToRegistry :: ByteString -> DateTime -> Either Text MetadataServiceRegistry
metadataBlobToRegistry ByteString
bytes DateTime
now = do
HashMap Text Value
json <- case ByteString
-> RootCertificate
-> DateTime
-> Either ProcessingError (HashMap Text Value)
Service.jwtToJson ByteString
bytes RootCertificate
Service.fidoAllianceRootCertificate DateTime
now of
Left ProcessingError
err -> Text -> Either Text (HashMap Text Value)
forall a b. a -> Either a b
Left (Text -> Either Text (HashMap Text Value))
-> Text -> Either Text (HashMap Text Value)
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ ProcessingError -> String
forall a. Show a => a -> String
show ProcessingError
err
Right HashMap Text Value
res -> HashMap Text Value -> Either Text (HashMap Text Value)
forall (f :: * -> *) a. Applicative f => a -> f a
pure HashMap Text Value
res
MetadataPayload
payload <- HashMap Text Value -> Either Text MetadataPayload
Service.jsonToPayload HashMap Text Value
json
MetadataServiceRegistry -> Either Text MetadataServiceRegistry
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MetadataServiceRegistry -> Either Text MetadataServiceRegistry)
-> MetadataServiceRegistry -> Either Text MetadataServiceRegistry
forall a b. (a -> b) -> a -> b
$ [SomeMetadataEntry] -> MetadataServiceRegistry
Service.createMetadataRegistry ([SomeMetadataEntry] -> MetadataServiceRegistry)
-> [SomeMetadataEntry] -> MetadataServiceRegistry
forall a b. (a -> b) -> a -> b
$ MetadataPayload -> [SomeMetadataEntry]
Service.mpEntries MetadataPayload
payload