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 -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show ProcessingError
err
Right HashMap Text Value
res -> 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
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [SomeMetadataEntry] -> MetadataServiceRegistry
Service.createMetadataRegistry forall a b. (a -> b) -> a -> b
$ MetadataPayload -> [SomeMetadataEntry]
Service.mpEntries MetadataPayload
payload