class OneSecret::Secret

Public Class Methods

key=(key) click to toggle source
# File lib/one_secret/secret.rb, line 10
def key=(key)
  Encryptor.default_options.merge!({key: key})
end
load(encrypted_value) click to toggle source
# File lib/one_secret/secret.rb, line 30
def self.load(encrypted_value)
  Encryptor.decrypt(encrypted_value) rescue encrypted_value
end
new(value) click to toggle source
# File lib/one_secret/secret.rb, line 15
def initialize(value)
  @iv = SecureRandom.hex(16)
  @salt = Time.now.to_i.to_s
  @value = Encryptor.encrypt(to_hash.merge(value: value))
end
unlocked() { || ... } click to toggle source
# File lib/one_secret/secret.rb, line 4
def unlocked
  self.key = KeyResolution.try(:env, :rails, :stdin)
  yield
  self.key = nil
end

Public Instance Methods

to_hash() click to toggle source
# File lib/one_secret/secret.rb, line 21
def to_hash
  {
    value: @value,
    iv: @iv,
    salt: @salt,
    algorithm: Encryptor.default_options[:algorithm]
  }
end