Class: Yasst::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/yasst/provider.rb,
lib/yasst/provider/openssl.rb

Overview

Represents a Crypto Provider

Parameters

  • passphrase The passphrase used for the provider instance. This is optional since some providers may not require a passphrase. Where passphrase is given, it must conform to minimum complexity requirements.

Direct Known Subclasses

OpenSSL

Defined Under Namespace

Classes: OpenSSL

Constant Summary collapse

PASSPHRASE_MIN_LENGTH =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Provider

Returns a new instance of Provider.



16
17
18
19
# File 'lib/yasst/provider.rb', line 16

def initialize(**args)
  self.passphrase = args[:passphrase]
  post_initialize(args)
end

Instance Attribute Details

#passphraseObject

Returns the value of attribute passphrase.



12
13
14
# File 'lib/yasst/provider.rb', line 12

def passphrase
  @passphrase
end

Instance Method Details

#passphrase_required?Boolean

Whether or not a passphrase is required for this provider instance Should be overridden in the provider subclass if it requires a passphrase

Returns:

  • (Boolean)


42
43
44
# File 'lib/yasst/provider.rb', line 42

def passphrase_required?
  false
end

#passphrase_valid?(pass = @passphrase) ⇒ Boolean

Validate a passphrase

Parameters
  • pass String. The passphrase to be validated

Returns
  • true/false if the passphrase is valid or not

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/yasst/provider.rb', line 52

def passphrase_valid?(pass = @passphrase)
  if pass.nil?
    return false if passphrase_required?
    return true
  end
  return false unless pass.length >= PASSPHRASE_MIN_LENGTH
  true
end

#post_initialize(**_args) ⇒ Object

post initialize hook for subclasses



22
23
24
# File 'lib/yasst/provider.rb', line 22

def post_initialize(**_args)
  nil
end

#validate_passphrase(pass = @passphrase) ⇒ Object

validates a passphrase and raise on error



32
33
34
35
36
37
38
# File 'lib/yasst/provider.rb', line 32

def validate_passphrase(pass = @passphrase)
  unless passphrase_valid?(pass)
    raise Yasst::Error::InvalidPassPhrase,
          'Passphrase does not meet minimum requirements'
  end
  true
end