Copyright | (c) 2019-2023 Emily Pillmore |
---|---|
License | BSD-style |
Maintainer | Emily Pillmore <emilypi@cohomolo.gy>, sofia-m-a <https://github.com/sofia-m-a> |
Stability | stable |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data Alphabet
- data Base64 (k :: Alphabet) a
- assertBase64 :: forall k a. a -> Base64 k a
- extractBase64 :: Base64 k a -> a
- coerceBase64 :: forall j k a. Base64 k a -> Base64 j a
- type family UrlAlphabet k :: Constraint where ...
- type family StdAlphabet k :: Constraint where ...
- type family NonStandardAlphabet k :: Constraint where ...
Documentation
The different kinds of supported Base64 encodings
StdPadded | Standard base64 according to RFC 4648 §4 Padding is always inserted when encoding, and required when decoding |
UrlPadded | Standard base64 according to RFC 4648 §4 Padding is never inserted when encoding, and optional when decoding per RFC 7049. |
UrlUnpadded | URL-safe base64 according to RFC 4648 §5 aka base64url Padding is never inserted when encoding, and optional when decoding |
NonStandard | Any non-standard, non RFC 4648-compliant base64 encoding. Can only be decoded using lenient decoders. |
data Base64 (k :: Alphabet) a Source #
Wraps a value, asserting that it is or is intended to be
in a particular kind of Base64 encoding use extractBase64
to extract the value, and assertBase64
to tag a value
as base64-encoded
assertBase64 :: forall k a. a -> Base64 k a Source #
Assert the provenance of a value encoded in a particular base64 alphabet.
Warning: This is a blind assertion that a particular
value is base64 encoded in some alphabet. If you are not
sure of the provenance of the value, you may experience
odd behavior when attempting to decode. Use at your own
risk. If I see any issues logged on this project from
negligent use of this or coerceBase64
, I will
smite you.
extractBase64 :: Base64 k a -> a Source #
Forget the provenance of a base64-encoded value.
coerceBase64 :: forall j k a. Base64 k a -> Base64 j a Source #
Coerce the alphabet of a base64-encoded bytestring
Warning: This is a blind assertion that a particular
value is base64 encoded in some alphabet. If you are not
sure of the provenance of the value, you may experience
odd behavior when attempting to decode. Use at your own
risk. If I see any issues logged on this project from
negligent use of this or assertBase64
, I will
smite you.
type family UrlAlphabet k :: Constraint where ... Source #
The type family of Url-safe alphabets
This type family defines the union of compatible Url-safe base64 types. To write a function that is parametric over such types, issue a constraint like `forall k. UrlAlphabet k`.
UrlAlphabet 'UrlPadded = () | |
UrlAlphabet 'UrlUnpadded = () | |
UrlAlphabet _ = TypeError ('Text "Cannot prove base64 value is encoded using the url-safe alphabet. Please re-encode using the url-safe encoders, or use a lenient decoder for the url-safe alphabet instead.") |
type family StdAlphabet k :: Constraint where ... Source #
The type family of standard alphabets
This type family defines the union of compatible standard alphabet base64 types
StdAlphabet 'StdPadded = () | |
StdAlphabet _ = TypeError ('Text "Cannot prove base64 value is encoded using the std alphabet. Please re-encode using the std encoders, or use a lenient decoder for the std alphabet instead.") |
type family NonStandardAlphabet k :: Constraint where ... Source #
The type family of non-standard alphabets
Only untyped variants of encodeBase64/decodeBase64 can interact with this type family, in addition to assertion/coercion/extraction of these types of values.
NonStandardAlphabet 'NonStandard = () | |
NonStandardAlphabet _ = TypeError ('Text "Cannot prove base64 value is encoded using a non-standard alphabet. Please re-encode and assert/coerce the alphabet, and use a lenient decoder.") |