Sha256: fabc1bd5b61edc10596f946e08272b0e8a3f6a3a37a9346e20ae41833aeac30a

Contents?: true

Size: 911 Bytes

Versions: 7

Compression:

Stored size: 911 Bytes

Contents

class Nanook
  class Key

    def initialize(rpc, key=nil)
      @rpc = rpc
      @key = key
    end

    def generate(seed: nil, index: nil)
      if seed.nil? && index.nil?
        rpc(:key_create)
      elsif !seed.nil? && !index.nil?
        rpc(:deterministic_key, seed: seed, index: index)
      else
        raise ArgumentError.new("This method must be called with either seed AND index params given or no params")
      end
    end

    def id
      @key
    end

    def info
      key_required!
      rpc(:key_expand)
    end

    def inspect
      "#{self.class.name}(id: \"#{id}\", object_id: \"#{"0x00%x" % (object_id << 1)}\")"
    end

    private

    def rpc(action, params={})
      p = @key.nil? ? {} : { key: @key }
      @rpc.call(action, p.merge(params))
    end

    def key_required!
      if @key.nil?
        raise ArgumentError.new("Key must be present")
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nanook-2.5.1 lib/nanook/key.rb
nanook-2.5.0 lib/nanook/key.rb
nanook-2.4.0 lib/nanook/key.rb
nanook-2.3.0 lib/nanook/key.rb
nanook-2.2.0 lib/nanook/key.rb
nanook-2.1.0 lib/nanook/key.rb
nanook-2.0.0 lib/nanook/key.rb