HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Modulecrypton-2.1.7Haskell2010

Crypto.Data.Padding

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

  • 1 type
  • 2 values
  • Packagecrypton-2.1.7
  • Exports3
  • LanguageHaskell2010
  • LicenceBSD-3-Clause AND MIT AND ISC
  • SourcePadding.hs
datadata Format
#

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.

Instances2Eq, Show
  • Eq FormatDefined in crypton-2.1.7 · Crypto.Data.Padding
  • Show FormatDefined in crypton-2.1.7 · Crypto.Data.Padding
valuepad :: ByteArray byteArray => Format -> byteArray -> byteArray
#

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.

valueunpad :: ByteArray byteArray => Format -> byteArray -> Maybe byteArray
#

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.