Class List Method List File List

# Class: ROTP::Base32

Inherits:
  Object
  - Object
  - ROTP::Base32
  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)

- + (Object) decode(str)
- + (Object) random_base32(length = 16)

## Class Method Details

### + (`Object`) decode(str)

    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

### + (`Object`) random_base32(length = 16)

    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