diff options
| -rw-r--r-- | lib/leap_cli/version.rb | 6 | ||||
| -rw-r--r-- | vendor/base32/LICENSE | 19 | ||||
| -rw-r--r-- | vendor/base32/base32.gemspec | 10 | ||||
| -rw-r--r-- | vendor/base32/lib/base32.rb | 67 | 
4 files changed, 101 insertions, 1 deletions
| diff --git a/lib/leap_cli/version.rb b/lib/leap_cli/version.rb index 2d7040f..31bf729 100644 --- a/lib/leap_cli/version.rb +++ b/lib/leap_cli/version.rb @@ -4,6 +4,10 @@ module LeapCli      COMPATIBLE_PLATFORM_VERSION = '0.8'..'0.99'      SUMMARY = 'Command line interface to the LEAP platform'      DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.' -    LOAD_PATHS = ['lib', 'vendor/certificate_authority/lib', 'vendor/rsync_command/lib'] +    LOAD_PATHS = ['lib', +      'vendor/certificate_authority/lib', +      'vendor/rsync_command/lib', +      'vendor/base32/lib' +    ]    end  end diff --git a/vendor/base32/LICENSE b/vendor/base32/LICENSE new file mode 100644 index 0000000..cdc04d9 --- /dev/null +++ b/vendor/base32/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2007-2011 Samuel Tesla + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/base32/base32.gemspec b/vendor/base32/base32.gemspec new file mode 100644 index 0000000..4e84cea --- /dev/null +++ b/vendor/base32/base32.gemspec @@ -0,0 +1,10 @@ +$:.push File.expand_path('../lib', __FILE__) + +Gem::Specification.new do |s| +  s.name    = 'base32' +  s.version = '0.3.2' +  s.authors = ['Samuel Tesla'] +  s.email   = 'samuel.tesla@gmail.com' +  s.summary = 'Ruby extension for base32 encoding and decoding' +  s.require_paths = ['lib'] +end diff --git a/vendor/base32/lib/base32.rb b/vendor/base32/lib/base32.rb new file mode 100644 index 0000000..4df2b1a --- /dev/null +++ b/vendor/base32/lib/base32.rb @@ -0,0 +1,67 @@ +require 'openssl' + +# Module for encoding and decoding in Base32 per RFC 3548 +module Base32 +  TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'.freeze + +  class Chunk +    def initialize(bytes) +      @bytes = bytes +    end + +    def decode +      bytes = @bytes.take_while {|c| c != 61} # strip padding +      n = (bytes.length * 5.0 / 8.0).floor +      p = bytes.length < 8 ? 5 - (n * 8) % 5 : 0 +      c = bytes.inject(0) {|m,o| (m << 5) + Base32.table.index(o.chr)} >> p +      (0..n-1).to_a.reverse.collect {|i| ((c >> i * 8) & 0xff).chr} +    end + +    def encode +      n = (@bytes.length * 8.0 / 5.0).ceil +      p = n < 8 ? 5 - (@bytes.length * 8) % 5 : 0 +      c = @bytes.inject(0) {|m,o| (m << 8) + o} << p +      [(0..n-1).to_a.reverse.collect {|i| Base32.table[(c >> i * 5) & 0x1f].chr}, +       ("=" * (8-n))] +    end +  end + +  def self.chunks(str, size) +    result = [] +    bytes = str.bytes +    while bytes.any? do +      result << Chunk.new(bytes.take(size)) +      bytes = bytes.drop(size) +    end +    result +  end + +  def self.encode(str) +    chunks(str, 5).collect(&:encode).flatten.join +  end + +  def self.decode(str) +    chunks(str, 8).collect(&:decode).flatten.join +  end + +  def self.random_base32(length=16, padding=true) +    random = '' +    OpenSSL::Random.random_bytes(length).each_byte do |b| +      random << self.table[b % 32] +    end +    padding ? random.ljust((length / 8.0).ceil * 8, '=') : random +  end + +  def self.table=(table) +    raise ArgumentError, "Table must have 32 unique characters" unless self.table_valid?(table) +    @table = table +  end + +  def self.table +    @table || TABLE +  end + +  def self.table_valid?(table) +    table.bytes.to_a.size == 32 && table.bytes.to_a.uniq.size == 32 +  end +end | 
