Class: Yasst::Provider::OpenSSL

Inherits:
Yasst::Provider show all
Includes:
Yasst::Primatives::OpenSSL
Defined in:
lib/yasst/provider/openssl.rb

Overview

OpenSSL provider

Parameters
  • profile

Required Parameters
  • passphrase

Constant Summary

Constants inherited from Yasst::Provider

PASSPHRASE_MIN_LENGTH

Instance Attribute Summary collapse

Attributes inherited from Yasst::Provider

#passphrase

Instance Method Summary collapse

Methods inherited from Yasst::Provider

#initialize, #passphrase_valid?, #validate_passphrase

Constructor Details

This class inherits a constructor from Yasst::Provider

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



14
15
16
# File 'lib/yasst/provider/openssl.rb', line 14

def profile
  @profile
end

Instance Method Details

#decrypt(string) ⇒ Object

De-encode, unpack and decrypt a string

Parameters
  • string A base64-encoded string to decrypt. Must be in the same format as the encrypt method produces

Returns


55
56
57
58
59
60
61
62
63
# File 'lib/yasst/provider/openssl.rb', line 55

def decrypt(string)
  d_salt, d_iv, ciphertext = p_unpack_string(
    string,
    profile.key_len,
    profile.iv_len,
    profile.salt_bytes
  )
  p_decrypt_string(ciphertext, key(d_salt), d_iv, profile.algorithm)
end

#encrypt(string) ⇒ Object

Encrypt a string using a unique salt + key for every encrypt action, and then package it up in a usable base64’d string with iv + salt prepended

Parameters
  • string A string to encrypt

Returns
  • String



40
41
42
43
44
45
# File 'lib/yasst/provider/openssl.rb', line 40

def encrypt(string)
  e_salt = salt
  e_key = key(e_salt)
  e_iv, ciphertext = p_encrypt_string(string, e_key, profile.algorithm)
  p_pack_string(e_iv, e_salt, ciphertext)
end

#passphrase_required?Boolean

Whether or not a passphrase is required for this provider

Returns:

  • (Boolean)


26
27
28
# File 'lib/yasst/provider/openssl.rb', line 26

def passphrase_required?
  true
end

#post_initialize(**args) ⇒ Object

initialize hook for superclass



18
19
20
21
22
# File 'lib/yasst/provider/openssl.rb', line 18

def post_initialize(**args)
  args[:profile].nil? && (@profile = Yasst::Profiles::OpenSSL.new) ||
    (@profile = args[:profile])
  validate_passphrase(@passphrase)
end