Skip to content

Commit

Permalink
add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
emilypi committed Jan 6, 2020
1 parent d3222ce commit c5fdd8d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Data/ByteString/Base64/URL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import Data.Text (Text)
encodeBase64 :: ByteString -> ByteString
encodeBase64 = encodeBase64_ True base64UrlTable

-- | Decode a padded base64-url encoded 'ByteString'
-- | Decode a padded base64-url encoded 'ByteString'. If its length is not a multiple
-- of 4, then padding chars will be added to fill out the input to a multiple of
-- 4 for safe decoding.
--
-- See: <https://tools.ietf.org/html/rfc4648#section-4 RFC-4648 section 4>
--
decodeBase64 :: ByteString -> Either Text ByteString
decodeBase64 = decodeBase64_ False decodeB64UrlTable
decodeBase64 = decodeBase64_ True decodeB64UrlTable

-- | Encode a 'ByteString' in base64-url without padding. Note that for Base64url,
-- padding is optional. If you call this function, you will simply be encoding
Expand All @@ -51,10 +53,12 @@ encodeBase64Unpadded :: ByteString -> ByteString
encodeBase64Unpadded = BS.takeWhile ((/=) 0x3d) . encodeBase64_ True base64UrlTable

-- | Decode an unpadded base64-url encoded 'ByteString'. If its length is not a multiple
-- of 4, then padding chars will be added to fill out the input to a multiple of
-- 4 for safe decoding.
-- of 4, then padding chars will __not__ be added to fill out the bytestring.
--
-- Only call this function if you are sure your bytestring length is a multiple of 4.
-- Otherwise, use the standard decoding function.
--
-- See: <https://tools.ietf.org/html/rfc4648#section-4 RFC-4648 section 4>
--
decodeBase64Unpadded :: ByteString -> Either Text ByteString
decodeBase64Unpadded = decodeBase64_ True decodeB64UrlTable
decodeBase64Unpadded = decodeBase64_ False decodeB64UrlTable

0 comments on commit c5fdd8d

Please sign in to comment.