Sha256: 4a69b01eb77308da37531e34ee15d78955a884b8b3ac3fb0f1b62803e9425a55

Contents?: true

Size: 808 Bytes

Versions: 7

Compression:

Stored size: 808 Bytes

Contents

require 'mongoid/kms'

module Mongoid
  module Kms
    module ClassMethods
      def encrypt_field(object, field_name, value)
        Rot13.rotate(value, 13)
      end

      def decrypt_field(object, field_name, data, encryption_context = nil)
        Rot13.rotate(data, -13)
      end
    end

    # inline Rot13 gem, as seen in
    # https://github.com/jrobertson/rot13/blob/012c9c37d767a364f793db00890dee82d9a65732/lib/rot13.rb
    # so we don't add unnecessary dependencies
    class Rot13
      def self.rotate(s,deg=13)
        a = ('a'..'z').map.with_index{|x,i| [x.chr,i] }

        r = s.split(//).map do |x|
          item = a.assoc(x.downcase)
          c = item ? a.rotate(deg)[item.last].first : x
          x == x.downcase ? c : c.upcase
        end
        r.join
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mongoid-kms-0.2.41 lib/mongoid/kms/mock.rb
mongoid-kms-0.2.40 lib/mongoid/kms/mock.rb
mongoid-kms-0.2.37 lib/mongoid/kms/mock.rb
mongoid-kms-0.0.36 lib/mongoid/kms/mock.rb
mongoid-kms-0.0.35 lib/mongoid/kms/mock.rb
mongoid-kms-0.1.4 lib/mongoid/kms/mock.rb
mongoid-kms-0.1.3 lib/mongoid/kms/mock.rb