Sha256: 76562c4ebc22076197331ac587ea73b0647b83707bcd7dd42cbba8f8763483f4

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module EnMail
  module EnMailable
    # Sign a message
    #
    # This interface allow us to sign a message while using this gem, this
    # also forecefully sets the `signable` status true, so it ensures that
    # the specific message will be signed before sending out.
    #
    # @param passphrase [String] the passphrase for the sign key
    # @param key [EnMail::Key] the key model instance
    #
    def sign(passphrase: "", key: nil)
      @key = key

      unless passphrase.empty?
        signing_key.passphrase = passphrase
      end
    end

    # Signing key
    #
    # This returns the signing key when applicable, the default signing
    # key is configured through an initializer, but we are also allowing
    # user to provide a custom key when they are invoking an interface.
    #
    # @return [EnMail::Key] the key model instance
    #
    def signing_key
      @key || EnMail.configuration.defualt_key
    end

    # Signing status
    #
    # This returns the message signing status based on the user specified
    # configuration and signing key. If the user enabled sign_message and
    # provided a valid signing key then this will return true otherwise
    # false, this can be used before trying to sing a message.
    #
    def signable?
      signing_key.sign_key && EnMail.configuration.signable?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enmail-0.1.0 lib/enmail/enmailable.rb