sandi-0.1.1: Data encoding library

Safe HaskellNone

Codec.Binary.Base32Hex

Description

Implemented as specified in RFC 4648 (http://tools.ietf.org/html/rfc4648).

This encoding is closely related to base 32 and so is its implementation, so please refer to Codec.Binary.Base32 for further details.

Synopsis

Documentation

b32h_encode_part :: ByteString -> (ByteString, ByteString)Source

Encoding function.

See b32_encode_part.

>>> b32h_encode_part $ Data.ByteString.Char8.pack "fooba"
("CPNMUOJ1","")
>>> b32h_encode_part $ Data.ByteString.Char8.pack "foobar"
("CPNMUOJ1","r")

b32h_encode_final :: ByteString -> Maybe ByteStringSource

Encoding function for the final block.

See b32_encode_final.

>>> b32h_encode_final $ Data.ByteString.Char8.pack "r"
Just "E8======"
>>> b32h_encode_final $ Data.ByteString.Char8.pack "fooba"
Nothing

b32h_decode_part :: ByteString -> Either (ByteString, ByteString) (ByteString, ByteString)Source

Decoding function.

See b32_decode_part.

>>> b32h_decode_part $ Data.ByteString.Char8.pack "CPNMUOJ1"
Right ("fooba","")
>>> b32h_decode_part $ Data.ByteString.Char8.pack "CPNMUOJ1E8======"
Right ("fooba","E8======")
>>> b32h_decode_part $ Data.ByteString.Char8.pack "C=NMUOJ1"
Left ("","C=NMUOJ1")

b32h_decode_final :: ByteString -> Maybe ByteStringSource

Decoding function for the final block.

See b32_decode_final.

>>> b32h_decode_final $ Data.ByteString.Char8.pack "CPNMUOG="
Just "foob"
>>> b32h_decode_final $ Data.ByteString.Char8.pack ""
Just ""
>>> b32h_decode_final $ Data.ByteString.Char8.pack "CPNMUO="
Nothing
>>> b32h_decode_final $ encode $ Data.ByteString.Char8.pack "fooba"
Nothing

encode :: ByteString -> ByteStringSource

Convenience function that combines b32h_encode_part and b32h_encode_final to encode a complete string.

>>> encode $ Data.ByteString.Char8.pack "fooba"
"CPNMUOJ1"
>>> encode $ Data.ByteString.Char8.pack "foobar"
"CPNMUOJ1E8======"

decode :: ByteString -> Either (ByteString, ByteString) ByteStringSource

Convenience function that combines b32h_decode_part and b32h_decode_final to decode a complete string.

>>> decode $ Data.ByteString.Char8.pack "CPNMUOJ1"
Right "fooba"
>>> decode $ Data.ByteString.Char8.pack "CPNMUOJ1E8======"
Right "foobar"

Failures when decoding returns the decoded part and the remainder:

>>> decode $ Data.ByteString.Char8.pack "CPNMUOJ1=8======"
Left ("fooba","=8======")