Sha256: 7b04af5a192e7531cba6a490d4b7b2bd8deec24011a9f509eb6f291cad0f2b07

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

require 'application.rb'
require 'crypto_rsa.rb'

class CryptoApp<Application
  def initialize(cluster,options)
    super
    @keys={}
    @myKey=options[:myKey]
    @myKey||=:my
    
    getMyKey # prefetch (generate)
  end
  
  def getKey(name)
    @keys[name]||=getKeyInternal(name)
  end
  
  def getMyKey
    getKey(@myKey)
  end
  
  private
  def getKeyInternal(name)
    # FIXME: add a layer inbetween ??
    name=name.to_s
    name.gsub!(/[^0-9A-Za-z_]*/,"")
    return nil if name.length==0
    filename="pk_#{name}"
    path=File.join(getAppDataPath,filename)
    if File.exists?(path)
      Crypto::Key.new(loadFile(path))
    elsif File.exists?(path+".pub")
      Crypto::Key.new(loadFile(path+".pub"))
    else
      createKey(name,path)
    end
  end
  def createKey(name,path)
    k=Crypto.create_keys
    k=Crypto::Key.new(k.to_s)
    k.save(path)
    k
  end
  def loadFile(f)
    File.open(f){|f|f.read}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 apps/crypto/crypto.rb