lib/ipcrypt/engine.rb in ipcrypt-1.0.0 vs lib/ipcrypt/engine.rb in ipcrypt-1.0.1

- old
+ new

@@ -1,17 +1,22 @@ require 'ipcrypt/exceptions' require 'securerandom' module IPCrypt class Engine - attr_reader :default_key + attr_reader :default_key, :ips IPv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ def initialize(*ips) @default_key = SecureRandom.random_bytes(16) @ips = ips.flatten.map do |ip| raise InvalidIPv4Error.new(ip) unless IPv4.match? ip ip end + end + + def ips=(ips) + @ips = ips if ips.is_a? Array + @ips = [ips] if ips.is_a? String end def encrypt(key = @default_key) raise InvalidKeyTypeError.new(key, key.class) unless key.is_a? String \ No newline at end of file