Sha256: 85f310e7c7e372a12c79dcaaf6ff6bd535e5adcbc96c8d8255efe17197ec0edf

Contents?: true

Size: 757 Bytes

Versions: 8

Compression:

Stored size: 757 Bytes

Contents

module KmsEncrypted
  module Clients
    class Test < Base
      PREFIX = Base64.decode64("insecure+data+A")

      def encrypt(plaintext, context: nil)
        parts = [PREFIX, Base64.strict_encode64(plaintext)]
        parts << generate_context(context) if context
        parts.join(":")
      end

      def decrypt(ciphertext, context: nil)
        prefix, plaintext, stored_context = ciphertext.split(":")

        decryption_failed! if prefix != PREFIX

        context = generate_context(context) if context
        decryption_failed! if context != stored_context

        Base64.decode64(plaintext)
      end

      private

      # turn hash into json
      def generate_context(context)
        Base64.encode64(super)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kms_encrypted-1.6.0 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.5.1 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.5.0 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.4.0 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.3.0 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.2.4 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.2.3 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.2.2 lib/kms_encrypted/clients/test.rb