Botan: Botan::PKCS7_Padding Class Reference

Botan 1.10.17

Public Member Functions | List of all members
Botan::PKCS7_Padding Class Reference

`#include <mode_pad.h>`

Inheritance diagram for Botan::PKCS7_Padding:

## Public Member Functions
std::string | name () const
void | pad (byte[], size_t, size_t) const
virtual size_t | pad_bytes (size_t block_size, size_t position) const
size_t | unpad (const byte[], size_t) const
bool | valid_blocksize (size_t) const

## Detailed Description

PKCS#7 Padding

Definition at line 72 of file mode_pad.h.

## Member Function Documentation

## ◆ name()

std::string Botan::PKCS7_Padding::name | ( |  | ) | const
| inlinevirtual

Returns
  name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 78 of file mode_pad.h.

Referenced by unpad().

78 { return "PKCS7"; }

## ◆ pad()

void Botan::PKCS7_Padding::pad | ( | byte | block[],
|  | size_t | size,
|  | size_t | current_position
| ) |  | const
| virtual

Parameters

  block | output buffer
  size | of the block
  current_position | in the last block

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 25 of file mode_pad.cpp.

References BOTAN_ASSERT_EQUAL.

26 {
27 const size_t bytes_remaining = size - position;
28 const byte pad_value = static_cast<byte>(bytes_remaining);
29
30 BOTAN_ASSERT_EQUAL(pad_value, bytes_remaining,
31 "Overflow in PKCS7_Padding");
32
33 for(size_t j = 0; j != size; ++j)
34 block[j] = pad_value;
35 }
Botan::byte
unsigned char byte
Definition: types.h:22
BOTAN_ASSERT_EQUAL
#define BOTAN_ASSERT_EQUAL(value1, value2, msg)
Definition: assert.h:29

## ◆ pad_bytes()

size_t Botan::BlockCipherModePaddingMethod::pad_bytes | ( | size_t | block_size,
|  | size_t | position
| ) |  | const
| virtualinherited

Parameters

  block_size | of the cipher
  position | in the current block

Returns
  number of padding bytes that will be appended

Reimplemented in Botan::Null_Padding.

Definition at line 17 of file mode_pad.cpp.

18 {
19 return (bs - pos);
20 }

## ◆ unpad()

size_t Botan::PKCS7_Padding::unpad | ( | const byte | block[],
|  | size_t | size
| ) |  | const
| virtual

Parameters

  block | the last block
  size | the of the block

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 40 of file mode_pad.cpp.

References name().

41 {
42 size_t position = block[size-1];
43 if(position > size)
44 throw Decoding_Error(name());
45 for(size_t j = size-position; j != size-1; ++j)
46 if(block[j] != position)
47 throw Decoding_Error(name());
48 return (size-position);
49 }
Botan::PKCS7_Padding::name
std::string name() const
Definition: mode_pad.h:78

## ◆ valid_blocksize()

bool Botan::PKCS7_Padding::valid_blocksize | ( | size_t | block_size | ) | const
| virtual

Parameters

  block_size | of the cipher

Returns
  valid block size for this padding mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 54 of file mode_pad.cpp.

55 {
56 if(size > 0 && size < 256)
57 return true;
58 else
59 return false;
60 }

The documentation for this class was generated from the following files:

- src/filters/modes/mode_pad/mode_pad.h
- src/filters/modes/mode_pad/mode_pad.cpp