crypton-2.2.5: Cryptography Primitives
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Crypto.Data.Padding

Description

Various cryptographic padding commonly used for block ciphers or asymmetric systems.

Synopsis

Documentation

data Format Source #

Format of padding

Constructors

PKCS5

PKCS5: PKCS7 with hardcoded size of 8

PKCS7 Int

PKCS7 with padding size between 1 and 255

ZERO Int

Zero padding with block size, which must be at least 1.

Zero padding does not say how much of it there is, so unpad cannot undo pad: see unpad.

Instances

Instances details
Show Format Source # 
Instance details

Defined in Crypto.Data.Padding

Eq Format Source # 
Instance details

Defined in Crypto.Data.Padding

Methods

(==) :: Format -> Format -> Bool #

(/=) :: Format -> Format -> Bool #

pad :: ByteArray byteArray => Format -> byteArray -> byteArray Source #

Apply some pad to a bytearray

A PKCS7 block size outside 1..255, or a ZERO block size below 1, raises an error; unpad reports the same condition as Nothing.

unpad :: ByteArray byteArray => Format -> byteArray -> Maybe byteArray Source #

Try to remove some padding from a bytearray.

PKCS7 padding says how long it is, so this undoes pad exactly.

ZERO padding says nothing, and pad adds none at all when the input is already a multiple of the block size, so there is no way to tell padding from data that happens to end in zero octets. This therefore does not undo pad: it returns the input unchanged when the last octet is not zero, and Nothing when it is, rather than guess and hand back less than it was given. Zero padding is only usable where the original length is known by other means.