Class: ROTP::Base32

Inherits:
Object
  • Object
show all
Defined in:
lib/rotp/base32.rb

Defined Under Namespace

Classes: Base32Error

Constant Summary collapse

CHARS =
'abcdefghijklmnopqrstuvwxyz234567'.each_char.to_a

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/rotp/base32.rb', line 7

def decode(str)
  str = str.tr('=', '')
  output = []
  str.scan(/.{1,8}/).each do |block|
    char_array = decode_block(block).map(&:chr)
    output << char_array
  end
  output.join
end

.random_base32(length = 32) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/rotp/base32.rb', line 17

def random_base32(length = 32)
  b32 = ''
  SecureRandom.random_bytes(length).each_byte do |b|
    b32 << CHARS[b % 32]
  end
  b32
end