Class: Pione::Relay::RelayAccountDB
- Inherits:
-
Object
- Object
- Pione::Relay::RelayAccountDB
- Extended by:
- Forwardable
- Defined in:
- lib/pione/relay/relay-account-db.rb
Defined Under Namespace
Classes: Account
Instance Method Summary collapse
- #add(realm, name, password) ⇒ Object
- #delete(realm) ⇒ Object
-
#initialize(path) ⇒ RelayAccountDB
constructor
A new instance of RelayAccountDB.
- #realms ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(path) ⇒ RelayAccountDB
Returns a new instance of RelayAccountDB.
10 11 12 13 14 |
# File 'lib/pione/relay/relay-account-db.rb', line 10 def initialize(path) raise TypeError.new(path) unless path.kind_of?(Pathname) @path = path @table = read_database end |
Instance Method Details
#add(realm, name, password) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/pione/relay/relay-account-db.rb', line 16 def add(realm, name, password) # stretching x 1000 digest = (1..1000).inject("") {|hash, _| Digest::SHA512.hexdigest("%s:%s:%s" % [hash, name, password]) } @table[realm] = Account.new(name, digest) end |
#delete(realm) ⇒ Object
24 25 26 27 |
# File 'lib/pione/relay/relay-account-db.rb', line 24 def delete(realm) @table.delete(realm) save end |
#realms ⇒ Object
29 30 31 |
# File 'lib/pione/relay/relay-account-db.rb', line 29 def realms @table.keys end |
#save ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/pione/relay/relay-account-db.rb', line 33 def save @path.open("w+", 0600) do |f| @table.each do |realm, account| f.puts "%s:%s:%s" % [realm, account.name, account.digest] if realm and account end end end |