-- | Stability: experimental
-- This module defines default values for fields of webauthn structures that
-- are optional but have a default specified. The identifiers here all have the
-- pattern of @<field>Default@ indicating that this is the default value for
-- field @<field>@ defined in 'Crypto.WebAuthn.Model.Types'
--
-- These default values are used when the respective fields are missing during
-- decoding. They may also be used by relying parties that don't want to set
-- the respective fields to their default. This is needed because defaults for
-- such fields can't be easily mapped to Haskell's records, see
-- "Crypto.WebAuthn.Model.Types#defaultFields"
module Crypto.WebAuthn.Model.Defaults
  ( ascUserVerificationDefault,
    ascResidentKeyDefault,
    corAttestationDefault,
    corExcludeCredentialsDefault,
    coaUserVerificationDefault,
    coaAllowCredentialsDefault,
  )
where

import qualified Crypto.WebAuthn.Model.Types as M

-- | [(spec)](https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-userverification)
-- Returns the default of the field 'M.ascUserVerification'
ascUserVerificationDefault :: M.UserVerificationRequirement
ascUserVerificationDefault :: UserVerificationRequirement
ascUserVerificationDefault = UserVerificationRequirement
M.UserVerificationRequirementPreferred

-- | [(spec)](https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-residentkey)
-- Returns the default of the field 'M.ascResidentKey' based on the
-- value of [@requireResidentKey@](https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey)
ascResidentKeyDefault :: Maybe Bool -> M.ResidentKeyRequirement
ascResidentKeyDefault :: Maybe Bool -> ResidentKeyRequirement
ascResidentKeyDefault (Just Bool
True) = ResidentKeyRequirement
M.ResidentKeyRequirementRequired
ascResidentKeyDefault Maybe Bool
_ = ResidentKeyRequirement
M.ResidentKeyRequirementDiscouraged

-- | [(spec)](https://www.w3.org/TR/webauthn-2/#dom-publickeycredentialcreationoptions-attestation)
-- Returns the default of the field 'M.corAttestation'
corAttestationDefault :: M.AttestationConveyancePreference
corAttestationDefault :: AttestationConveyancePreference
corAttestationDefault = AttestationConveyancePreference
M.AttestationConveyancePreferenceNone

-- | [(spec)](https://www.w3.org/TR/webauthn-2/#dom-publickeycredentialcreationoptions-excludecredentials)
-- Returns the default of the field 'M.corExcludeCredentials'
corExcludeCredentialsDefault :: [M.CredentialDescriptor]
corExcludeCredentialsDefault :: [CredentialDescriptor]
corExcludeCredentialsDefault = []

-- | [(spec)](https://www.w3.org/TR/webauthn-2/#dom-publickeycredentialrequestoptions-userverification)
-- Returns the default of the field 'M.coaUserVerification'
coaUserVerificationDefault :: M.UserVerificationRequirement
coaUserVerificationDefault :: UserVerificationRequirement
coaUserVerificationDefault = UserVerificationRequirement
M.UserVerificationRequirementPreferred

-- | [(spec)](https://www.w3.org/TR/webauthn-2/#dom-publickeycredentialrequestoptions-allowcredentials)
-- Returns the default of the field 'M.coaAllowCredentials'
coaAllowCredentialsDefault :: [M.CredentialDescriptor]
coaAllowCredentialsDefault :: [CredentialDescriptor]
coaAllowCredentialsDefault = []