| 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.ByteString.Lazy.Base64
Description
This module contains ByteString-valued combinators for
implementing the RFC 4648 specification of the Base64
encoding format. This includes lenient decoding variants, as well as
internal and external validation for canonicity.
Synopsis
- encodeBase64 :: ByteString -> Base64 'StdPadded Text
- encodeBase64' :: ByteString -> Base64 'StdPadded ByteString
- decodeBase64 :: forall (k :: Alphabet). StdAlphabet k => Base64 k ByteString -> ByteString
- decodeBase64Untyped :: ByteString -> Either Text ByteString
- decodeBase64Lenient :: ByteString -> ByteString
- parseBase64 :: ByteString -> Either Text (Base64 'StdPadded ByteString)
Encoding
encodeBase64 :: ByteString -> Base64 'StdPadded Text Source #
Encode a ByteString value as Base64 Text with padding.
See: RFC-4648 section 4
Examples:
>>>encodeBase64 "Sun""U3Vu"
encodeBase64' :: ByteString -> Base64 'StdPadded ByteString Source #
Encode a ByteString value as a Base64 ByteString value with padding.
See: RFC-4648 section 4
Examples:
>>>encodeBase64' "Sun""U3Vu"
Decoding
decodeBase64 :: forall (k :: Alphabet). StdAlphabet k => Base64 k ByteString -> ByteString Source #
Decode a padded Base64-encoded ByteString value.
See: RFC-4648 section 4
Examples:
>>>decodeBase64 $ assertBase64 @'StdPadded "U3Vu""Sun"
decodeBase64Untyped :: ByteString -> Either Text ByteString Source #
Decode a padded untyped Base64-encoded ByteString value.
See: RFC-4648 section 4
Examples:
>>>decodeBase64Untyped "U3Vu"Right "Sun"
>>>decodeBase64Untyped "U3V"Left "Base64-encoded bytestring requires padding"
>>>decodeBase64Untyped "U3V="Left "non-canonical encoding detected at offset: 2"
decodeBase64Lenient :: ByteString -> ByteString Source #
Leniently decode an unpadded Base64-encoded ByteString value. This function
will not generate parse errors. If input data contains padding chars,
then the input will be parsed up until the first pad character.
Note: This is not RFC 4648-compliant.
Examples:
>>>decodeBase64Lenient "U3Vu""Sun"
>>>decodeBase64Lenient "U3V""Su"
>>>decodeBase64Lenient "U3V=""Su"
Parsing
parseBase64 :: ByteString -> Either Text (Base64 'StdPadded ByteString) Source #
Parse a canonical, padded Base64-encoded ByteString value.
Checks the alphabet, length, padding, and unused padding bits. On success,
returns the original encoded value wrapped in Base64, ready for
decodeBase64. On failure, returns the same error as decodeBase64Untyped.
The input is neither decoded nor normalized in the returned value.
The entire input is validated before returning Right; the original
chunk boundaries are preserved in the result.
Examples:
>>>parseBase64 "U3Vu"Right "U3Vu"
>>>fmap decodeBase64 (parseBase64 "U3Vu")Right "Sun"
>>>parseBase64 "U3V"Left "Base64-encoded bytestring requires padding"
>>>parseBase64 "U3V="Left "non-canonical encoding detected at offset: 2"
Since: 2.0