memory-0.15.0: memory and related abstraction stuff
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Data.ByteArray.Encoding

Description

Base conversions for ByteArray.

Synopsis

Documentation

convertToBase :: (ByteArrayAccess bin, ByteArray bout) => Base -> bin -> bout Source #

Encode some bytes to the equivalent representation in a specific Base.

Examples

Convert a ByteString to base-64:

>>> convertToBase Base64 ("foobar" :: ByteString) :: ByteString
"Zm9vYmFy"

convertFromBase :: (ByteArrayAccess bin, ByteArray bout) => Base -> bin -> Either String bout Source #

Try to decode some bytes from the equivalent representation in a specific Base.

Examples

Successfully convert from base-64 to a ByteString:

>>> convertFromBase Base64 ("Zm9vYmFy" :: ByteString) :: Either String ByteString
Right "foobar"

Trying to decode invalid data will return an error string:

>>> convertFromBase Base64 ("!!!" :: ByteString) :: Either String ByteString
Left "base64: input: invalid length"

data Base Source #

The different bases that can be used.

See RFC4648 for details. In particular, Base64 can be standard or URL-safe. URL-safe encoding is often used in other specifications without padding characters.

Examples

A quick example to show the differences:

>>> let input = "Is 3 > 2?" :: ByteString
>>> let convertedTo base = convertToBase base input :: ByteString
>>> convertedTo Base16
"49732033203e20323f"
>>> convertedTo Base32
"JFZSAMZAHYQDEPY="
>>> convertedTo Base64
"SXMgMyA+IDI/"
>>> convertedTo Base64URLUnpadded
"SXMgMyA-IDI_"
>>> convertedTo Base64OpenBSD
"QVKeKw.8GBG9"

Constructors

Base16

similar to hexadecimal

Base32 
Base64

standard Base64

Base64URLUnpadded

unpadded URL-safe Base64

Base64OpenBSD

Base64 as used in OpenBSD password encoding (such as bcrypt)

Instances

Instances details
Eq Base Source # 
Instance details

Defined in Data.ByteArray.Encoding

Methods

(==) :: Base -> Base -> Bool Source #

(/=) :: Base -> Base -> Bool Source #

Show Base Source # 
Instance details

Defined in Data.ByteArray.Encoding