lib/iocrypt.rb in gtk2passwordapp-0.0.6 vs lib/iocrypt.rb in gtk2passwordapp-0.0.7

- old
+ new

@@ -1,26 +1,36 @@ -# $Date: 2009/02/18 00:41:54 $ +# $Date: 2009/02/26 00:43:37 $ require 'yaml' require 'rubygems' require 'crypt/blowfish' class IOCrypt + HTTPX = Regexp.new('^https?:\/\/') + def initialize(passphrase) @blowfish = Crypt::Blowfish.new(passphrase[0..55]) end def load(dumpfile) data = nil - File.open(dumpfile,'r'){|fh| - data = YAML.load( @blowfish.decrypt_string( fh.read ) ) - } + if dumpfile =~ HTTPX then + require 'open-uri' + open(dumpfile){|fh| + data = YAML.load( @blowfish.decrypt_string( fh.read ) ) + } + else + File.open(dumpfile,'r'){|fh| + data = YAML.load( @blowfish.decrypt_string( fh.read ) ) + } + end return data end def dump(dumpfile, data) count = nil + raise "Http PUT not supported" if dumpfile =~ HTTPX File.open(dumpfile,'w') do |fh| count = fh.write( @blowfish.encrypt_string( YAML.dump( data ) ) ) end