Class: PGCrypto::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/pgcrypto/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Key

Returns a new instance of Key.



29
30
31
32
33
34
35
36
37
# File 'lib/pgcrypto/key.rb', line 29

def initialize(options = {})
  if options.is_a?(String)
    self.value = options
  elsif options.is_a?(Hash)
    options.each do |key, value|
      send("#{key}=", value)
    end
  end
end

Instance Attribute Details

#armored=(value) ⇒ Object (writeonly)

Sets the attribute armored

Parameters:

  • value

    the value to set the attribute armored to.



15
16
17
# File 'lib/pgcrypto/key.rb', line 15

def armored=(value)
  @armored = value
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/pgcrypto/key.rb', line 13

def name
  @name
end

#passwordObject

Returns the value of attribute password.



13
14
15
# File 'lib/pgcrypto/key.rb', line 13

def password
  @password
end

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/pgcrypto/key.rb', line 14

def path
  @path
end

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/pgcrypto/key.rb', line 13

def value
  @value
end

Instance Method Details

#armored?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pgcrypto/key.rb', line 17

def armored?
  @armored
end

#dearmoredObject



21
22
23
# File 'lib/pgcrypto/key.rb', line 21

def dearmored
  "#{'dearmor(' if armored?}'#{self}'#{')' if armored?}"
end

#encrypt(value) ⇒ Object



25
26
27
# File 'lib/pgcrypto/key.rb', line 25

def encrypt(value)
  %[pgp_pub_encrypt('#{value}', #{dearmored})]
end

#password?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/pgcrypto/key.rb', line 39

def password?
  ", '#{password}'" if password
end

#to_sObject



50
51
52
# File 'lib/pgcrypto/key.rb', line 50

def to_s
  value
end