Copyright | (c) 2019-2020 Emily Pillmore |
---|---|
License | BSD-style |
Maintainer | Emily Pillmore <emilypi@cohomolo.gy> |
Stability | Experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
This module contains the combinators implementing the RFC 4648 specification for the Base64 encoding including unpadded and lenient variants
Synopsis
- encodeBase64 :: ShortText -> ShortText
- decodeBase64 :: ShortText -> Either Text ShortText
- decodeBase64With :: (ShortByteString -> Either err ShortText) -> ShortByteString -> Either (Base64Error err) ShortText
- decodeBase64Lenient :: ShortText -> ShortText
- isBase64 :: ShortText -> Bool
- isValidBase64 :: ShortText -> Bool
Documentation
encodeBase64 :: ShortText -> ShortText Source #
Encode a ShortText
value in Base64 with padding.
See: RFC-4648 section 4
decodeBase64 :: ShortText -> Either Text ShortText Source #
Decode a padded Base64-encoded ShortText
value
Note: This function makes sure that decoding is total by deferring to
decodeLatin1
. This will always round trip for any valid Base64-encoded
text value, but it may not round trip for bad inputs. The onus is on the
caller to make sure inputs are valid. If unsure, defer to decodeBase64With
and pass in a custom decode function.
See: RFC-4648 section 4
:: (ShortByteString -> Either err ShortText) | convert a bytestring to text (e.g. |
-> ShortByteString | Input text to decode |
-> Either (Base64Error err) ShortText |
Attempt to decode a ShortByteString
value as Base64, converting from
ByteString
to ShortText
according to some encoding function. In practice,
This is something like decodeUtf8'
, which may produce an error.
See: RFC-4648 section 4
Example:
decodeBase64With
decodeUtf8'
::ShortByteString
->Either
(Base64Error
UnicodeException
)ShortText