Edda.Crypto
Cookie signing helpers and crypto re-exports used by Edda.
Signed cookies are tamper-evident but not encrypted. Store signing secrets
in configuration and use CookieSecrets when rotating keys.
Types
CookieSecret
opaque type CookieSecretOpaque signing secret used for signed cookie values.
CookieSecrets
record CookieSecrets {
current: CookieSecret,
previous: List CookieSecret
}Signing secrets for key rotation.
New cookies are signed with current; verification accepts current and
every secret in previous.
SignedCookieError
type SignedCookieError =
| SignedCookieMissing String
| SignedCookieBadFormat
| SignedCookieBadSignature
| SignedCookieValueNotUtf8
deriving (Debug, Eq)Errors returned while reading or verifying a signed cookie.
Functions
cookie_secret
fun cookie_secret : String -> CookieSecretBuild a cookie signing secret from a UTF-8 string.
Use a high-entropy random value from configuration in real applications.
cookie_secret_bytes
fun cookie_secret_bytes : BitString -> CookieSecretBuild a cookie signing secret from raw bytes.
cookie_secrets
fun cookie_secrets : CookieSecret -> CookieSecretsBuild a non-rotating secret set from the current signing secret.
cookie_secrets_with_previous
fun cookie_secrets_with_previous : CookieSecret -> List CookieSecret -> CookieSecretsBuild a rotating secret set. Signing uses current; verification also
accepts previous.
sign_cookie_value
fun sign_cookie_value : CookieSecret -> String -> StringSign a cookie value. The result is cookie-safe but not encrypted.
sign_cookie_value_with_secrets
fun sign_cookie_value_with_secrets : CookieSecrets -> String -> StringSign a cookie value with the current secret from a rotating secret set.
verify_cookie_value
fun verify_cookie_value : CookieSecret -> String -> Result String SignedCookieErrorVerify a signed cookie value and return the original unsigned value.
verify_cookie_value_with_secrets
fun verify_cookie_value_with_secrets : CookieSecrets -> String -> Result String SignedCookieErrorVerify a signed cookie value against the current and previous secrets.
signed_cookie
fun signed_cookie : CookieSecret -> String -> Request -> Result String SignedCookieErrorRead and verify a named cookie from the request.
signed_cookie_with_secrets
fun signed_cookie_with_secrets : CookieSecrets -> String -> Request -> Result String SignedCookieErrorRead and verify a named cookie against current and previous secrets.
set_signed_cookie
fun set_signed_cookie : CookieSecret -> String -> String -> Response -> ResponseAdd a signed cookie using default cookie options.
set_signed_cookie_with
fun set_signed_cookie_with : CookieSecret -> String -> String -> CookieOptions -> Response -> ResponseAdd a signed cookie using explicit cookie options.
set_signed_cookie_checked
fun set_signed_cookie_checked : CookieSecret -> String -> String -> Response -> Result Response CookieErrorAdd a signed cookie using default cookie options, validating the name.
set_signed_cookie_with_checked
fun set_signed_cookie_with_checked : CookieSecret -> String -> String -> CookieOptions -> Response -> Result Response CookieErrorAdd a signed cookie using explicit cookie options, validating the name.
set_signed_cookie_with_secrets
fun set_signed_cookie_with_secrets : CookieSecrets -> String -> String -> Response -> ResponseAdd a signed cookie with the current secret from a rotating secret set.
set_signed_cookie_with_secrets_and_options
fun set_signed_cookie_with_secrets_and_options : CookieSecrets -> String -> String -> CookieOptions -> Response -> ResponseAdd a signed cookie with rotating secrets and explicit cookie options.