Module: Cryptograpi

Defined in:
lib/cryptograpi_ruby/cipher.rb,
lib/cryptograpi_ruby/decrypt.rb,
lib/cryptograpi_ruby/encrypt.rb,
lib/cryptograpi_ruby/signature.rb,
lib/cryptograpi_ruby/credentials.rb

Defined Under Namespace

Classes: Cipher, ConfigCredentials, Credentials, Decryption, Encryption, Info, Signature

Instance Method Summary collapse

Instance Method Details

#decrypt(creds, data) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cryptograpi_ruby/decrypt.rb', line 187

def decrypt(creds, data)
  begin
    dec = Decryption.new(creds)
    res = dec.begin_decryption + dec.update_decryption(data) + dec.finish_decryption
    dec.close_decryption
  rescue StandardError
    dec&.close_decryption
    raise
  end

  res
end

#encrypt(credentials, data) ⇒ Object

Qui e!



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/cryptograpi_ruby/encrypt.rb', line 151

def encrypt(credentials, data)
  begin
    enc = Encryption.new(credentials, 1)
    res =
      enc.begin_encryption +
      enc.update_encryption(data) +
      enc.finish_encryption
    enc.close_encryption
  rescue StandardError
    enc&.close_encryption
    raise
  end
  res
end

#validate_credentials(credentials) ⇒ Object

Check credentials are present and valid



144
145
146
147
148
# File 'lib/cryptograpi_ruby/encrypt.rb', line 144

def validate_credentials(credentials)
  !credentials.access_key_id.blank? &&
    !credentials.secret_access_key.blank? &&
    !credentials.signing_key.blank?
end