Class: ROTP::Base32

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

Defined Under Namespace

Classes: Base32Error

Constant Summary

CHARS =
"abcdefghijklmnopqrstuvwxyz234567".each_char.to_a

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



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

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

.random_base32(length = 16) ⇒ Object



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

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