Class: Cap

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/extensions/ezcrypto/ext/test/active_crypto_test.rb

Class Method Summary collapse

Class Method Details

.create_for_asset(asset, email = nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/extensions/ezcrypto/ext/test/active_crypto_test.rb', line 68

def self.create_for_asset(asset,email=nil)
  cap=Cap.new
  cap.email=email if email
  cap.asset=asset
  if cap.save
    cap.set_session_key(EzCrypto::Key.generate)
    cap_key=cap.session_key.encode
    cap.key_hash=Digest::SHA1.hexdigest(cap_key)
    cap.shared_key=asset.session_key.encode
    cap.save
    cap_key
  else
    nil
  end
end

.find_by_key(cap_key) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/extensions/ezcrypto/ext/test/active_crypto_test.rb', line 53

def self.find_by_key(cap_key)
  cap_key.chop
  hash=Digest::SHA1.hexdigest(cap_key)
  if (cap_key.length>=20) # Sanity check
    cap=self.find_by_key_hash(hash)
    if cap
      cap.set_encoded_key(cap_key)
      cap.asset.set_encoded_key(cap.shared_key)
      cap
    end
  else
    nil
  end
end