class Subledger::Domain::Key

Attributes

bcrypt[R]
identity[R]
secret[R]

Public Class Methods

active_klass() click to toggle source
# File lib/subledger/domain/key.rb, line 36
def self.active_klass
  ActiveKey
end
archived_klass() click to toggle source
# File lib/subledger/domain/key.rb, line 40
def self.archived_klass
  ArchivedKey
end
new(args) click to toggle source
# File lib/subledger/domain/key.rb, line 44
def initialize args
  identifiable args
  storable args

  @identity = args[:identity]

  # TODO separate new and create

  if args[:bcrypt].nil?
    @secret = args[:secret] || UUID.as_string

    @bcrypt = BCrypt::Password.create( @secret, :cost => 5 )
  elsif args[:bcrypt]
    @secret = args[:secret]

    @bcrypt = BCrypt::Password.new args[:bcrypt]
  end
end
post_keys() click to toggle source
# File lib/subledger/domain/key.rb, line 24
def self.post_keys
  [ :id, :identity ]
end
root_klass() click to toggle source
# File lib/subledger/domain/key.rb, line 28
def self.root_klass
  Key
end
sub_klasses() click to toggle source
# File lib/subledger/domain/key.rb, line 32
def self.sub_klasses
  [ archived_klass, active_klass ]
end

Private Class Methods

raise_unless_creatable(args) click to toggle source
# File lib/subledger/domain/key.rb, line 82
def self.raise_unless_creatable args
  identity = args[:identity]

  if identity.nil? or not identity.kind_of? Identity
    raise KeyError, ':identity is required and must be an Identity'
  elsif UUID.invalid? identity.id
    raise KeyError, ':identity must have a valid :id'
  end
end

Public Instance Methods

authenticates?(this_secret) click to toggle source
# File lib/subledger/domain/key.rb, line 63
def authenticates? this_secret
  bcrypt == this_secret
end