Class: Zweifische::AnsiX923Padding

Inherits:
Object
  • Object
show all
Defined in:
lib/zweifische/ansi_x_923_padding.rb

Direct Known Subclasses

PKCS7Padding

Class Method Summary collapse

Class Method Details

.pad(num) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
# File 'lib/zweifische/ansi_x_923_padding.rb', line 4

def pad(num)
  raise ArgumentError.new("max pad is 16 bytes") if num > 15 || num < 0
  return "" if num == 0
  0x00.chr * (num - 1) + num.chr
end

.unpad(text) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/zweifische/ansi_x_923_padding.rb', line 10

def unpad(text)
  numpad = numpad(text)
  if assert_pad(text, numpad, 0x00.chr)
    return text[0..(-1 * (numpad + 1))]
  end
  text
end