Botan: Botan::OneAndZeros_Padding Class Reference

Botan 1.10.16

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

`#include <mode_pad.h>`

Inheritance diagram for Botan::OneAndZeros_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

One And Zeros Padding

Definition at line 96 of file mode_pad.h.

## Member Function Documentation

## ◆ name()

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

Returns
  name of the mode

Implements Botan::BlockCipherModePaddingMethod.

Definition at line 102 of file mode_pad.h.

102 { return "OneAndZeros"; }

## ◆ pad()

void Botan::OneAndZeros_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 100 of file mode_pad.cpp.

101 {
102 block[0] = 0x80;
103 for(size_t j = 1; j != size; ++j)
104 block[j] = 0x00;
105 }

## ◆ 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.

Referenced by Botan::ECB_Encryption::name(), and Botan::CBC_Encryption::set_iv().

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

## ◆ unpad()

size_t Botan::OneAndZeros_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 110 of file mode_pad.cpp.

References Botan::BlockCipherModePaddingMethod::name().

111 {
112 while(size)
113 {
114 if(block[size-1] == 0x80)
115 break;
116 if(block[size-1] != 0x00)
117 throw Decoding_Error(name());
118 size--;
119 }
120 if(!size)
121 throw Decoding_Error(name());
122 return (size-1);
123 }
Botan::OneAndZeros_Padding::name
std::string name() const
Definition: mode_pad.h:102

## ◆ valid_blocksize()

bool Botan::OneAndZeros_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 128 of file mode_pad.cpp.

129 {
130 return (size > 0);
131 }

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