Copyright | (c) K. Isom (2015) |
---|---|
License | BSD-style |
Maintainer | coder@kyleisom.net |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This implements the PKCS #7 padding scheme for String
s. This scheme is
defined in RFC 5652.
Strings will be padded out to multiples of the block size; for example, a 5-byte string with an 8-byte block size will have three bytes of padding added. If the length is already a multiple of the block size, an entire block size worth of padding is added.
The padding bytes are all set to the number of padding bytes. Returning to the previous example, the padding string would be three bytes of the byte 0x03.
Unpadding checks the length and padding, and if this is valid, strips off the padding.
- pad :: String -> String
- padN :: Int -> String -> String
- unpad :: String -> Maybe String
- unpadN :: Int -> String -> Maybe String
- padBytes :: ByteString -> ByteString
- padBytesN :: Int -> ByteString -> ByteString
- unpadBytes :: ByteString -> Maybe ByteString
- unpadBytesN :: Int -> ByteString -> Maybe ByteString
Documentation
pad :: String -> String Source
pad
applies the PKCS #7 padding scheme to the input string;
it uses the AES block size of 16 bytes as its block size.
padN :: Int -> String -> String Source
padN
applies the PKCS #7 padding scheme to the input string
given the blockSize
.
padBytes :: ByteString -> ByteString Source
pad
applies the PKCS #7 padding scheme to the input string;
it uses the AES block size of 16 bytes as its block size.
padBytesN :: Int -> ByteString -> ByteString Source
padBytesN
applies the PKCS #7 padding scheme to the input bytestring
given the blockSize
.
unpadBytes :: ByteString -> Maybe ByteString Source
unpadBytes
attempts to remove the padding from the input ByteString
,
assuming an AES block size of 16 bytes.
unpadBytesN :: Int -> ByteString -> Maybe ByteString Source
unpadBytesN
attempts to remove the blockSize
padding from its input
ByteString
. If the padding is invalid, Nothing
is returned.