| Copyright | (c) 2019-2026 Emily Pillmore |
|---|---|
| License | BSD-style |
| Maintainer | Emily Pillmore <emilypi@cohomolo.gy> |
| Stability | stable |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Base64.Types
Description
Synopsis
- data Alphabet
- data Base64 (k :: Alphabet) a
- assertBase64 :: forall (k :: Alphabet) a. a -> Base64 k a
- extractBase64 :: forall (k :: Alphabet) a. Base64 k a -> a
- coerceBase64 :: forall (j :: Alphabet) (k :: Alphabet) a. Base64 k a -> Base64 j a
- type family UrlAlphabet (k :: Alphabet) where ...
- type family StdAlphabet (k :: Alphabet) where ...
- type family NonStandardAlphabet (k :: Alphabet) where ...
Documentation
The different kinds of supported Base64 encodings. This library supports the encodings defined in RFC 4648 and RFC 7049.
RFC 2045 defines a separate Base64 encoding for MIME, which is not supported. This format requires a newline at least every 76 encoded characters, which works around limitations of older email programs that could not handle long lines. Be aware that other languages, such as Ruby, encode the RFC 2045 version by default. To decode their ouput, remove all newlines before decoding.
Constructors
| StdPadded | Standard base64 according to RFC 4648 §4 Padding is inserted when needed and required by the standard parser and decoder. |
| UrlPadded | URL-safe base64 according to RFC 4648 §5 aka base64url. Padding is inserted when needed and required by the padded parser and decoder. |
| UrlUnpadded | URL-safe base64 according to RFC 4648 §5 aka base64url Padding is never inserted and is rejected by the unpadded parser and decoder. |
| NonStandard | Any non-standard, non RFC 4648-compliant base64 encoding. Can only be decoded using lenient decoders. This marker does not define an alphabet or canonical validation rules. |
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 :: Alphabet) a. a -> Base64 k a Source #
Assert the provenance of a value encoded in a particular base64 alphabet.
For untrusted input, use parseBase64 for standard Base64, or
parseBase64Padded / parseBase64Unpadded for Base64url, in the
corresponding ByteString or Text module to validate it first.
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 :: forall (k :: Alphabet) a. Base64 k a -> a Source #
Forget the provenance of a base64-encoded value.
coerceBase64 :: forall (j :: Alphabet) (k :: Alphabet) 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 :: Alphabet) 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`.
Equations
| UrlAlphabet 'UrlPadded = () | |
| UrlAlphabet 'UrlUnpadded = () | |
| UrlAlphabet _1 = 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.") :: Constraint |
type family StdAlphabet (k :: Alphabet) where ... Source #
The type family of standard alphabets
This type family defines the union of compatible standard alphabet base64 types
Equations
| StdAlphabet 'StdPadded = () | |
| StdAlphabet _1 = 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.") :: Constraint |
type family NonStandardAlphabet (k :: Alphabet) 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.
Equations
| NonStandardAlphabet 'NonStandard = () | |
| NonStandardAlphabet _1 = 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.") :: Constraint |