<commit_before>require 'openssl'
require 'base64'

require File.join('encrypted_strings', 'encrypted_string')
require File.join('encrypted_strings', 'symmetrically_encrypted_string')
require File.join('encrypted_strings', 'asymmetrically_encrypted_string')
require File.join('encrypted_strings', 'sha_encrypted_string')

module PluginAWeek #:nodoc:
  module CoreExtensions #:nodoc:
    module String #:nodoc:
      module EncryptedStrings
        def self.included(base) #:nodoc:
          base.class_eval do
            alias_method :equals_without_encryption, :==
            alias_method :==, :equals_with_encryption
          end
        end
        
        # Encrypts the current string using the encryption algorithm specified.
        # The default encryption mode is sha.
        # 
        # Configuration options are encryption-specified.  See the encryption
        # class for that string to find out the options available.
        #
        def encrypt(*args)
          options = args.last.is_a?(::Hash) ? args.pop : {}
          mode = (args.first || :sha).to_sym
          
          send("encrypt_#{mode}", options)
        end
        
        # Encrypts the string using an SHA algorithm
        # 
        def encrypt_sha(options = {})
          create_encrypted_string(SHAEncryptedString, options)
        end
        
        # Encrypts the string using an asymmetric algorithm
        #
        def encrypt_asymmetrically(options = {})
          create_encrypted_string(AsymmetricallyEncryptedString, options)
        end
        alias_method :encrypt_asymmetric, :encrypt_asymmetrically
        
        # Encrypts the string using a symmetric algorithm
        #
        def encrypt_symmetrically(options = {})
          create_encrypted_string(SymmetricallyEncryptedString, options)
        end
        alias_method :encrypt_symmetric, :encrypt_symmetrically
        
        # Adds support for testing equality with an encrypted string
        #
        def equals_with_encryption(other)
          if other.is_a?(EncryptedString) && self.class == ::String
            other == self
          else
            equals_without_encryption(other)
          end
        end
        
        private
        def create_encrypted_string(klass, options) #:nodoc:
          klass.new(self, options)
        end
      end
    end
  end
end

::String.class_eval do
  include PluginAWeek::CoreExtensions::String::EncryptedStrings
end<commit_msg>Slight speed improvement for string equality override.<commit_after>require 'openssl'
require 'base64'

require File.join('encrypted_strings', 'encrypted_string')
require File.join('encrypted_strings', 'symmetrically_encrypted_string')
require File.join('encrypted_strings', 'asymmetrically_encrypted_string')
require File.join('encrypted_strings', 'sha_encrypted_string')

module PluginAWeek #:nodoc:
  module CoreExtensions #:nodoc:
    module String #:nodoc:
      module EncryptedStrings
        def self.included(base) #:nodoc:
          base.class_eval do
            alias_method :equals_without_encryption, :==
            alias_method :==, :equals_with_encryption
          end
        end
        
        # Encrypts the current string using the encryption algorithm specified.
        # The default encryption mode is sha.
        # 
        # Configuration options are encryption-specified.  See the encryption
        # class for that string to find out the options available.
        #
        def encrypt(*args)
          options = args.last.is_a?(::Hash) ? args.pop : {}
          mode = (args.first || :sha).to_sym
          
          send("encrypt_#{mode}", options)
        end
        
        # Encrypts the string using an SHA algorithm
        # 
        def encrypt_sha(options = {})
          create_encrypted_string(SHAEncryptedString, options)
        end
        
        # Encrypts the string using an asymmetric algorithm
        #
        def encrypt_asymmetrically(options = {})
          create_encrypted_string(AsymmetricallyEncryptedString, options)
        end
        alias_method :encrypt_asymmetric, :encrypt_asymmetrically
        
        # Encrypts the string using a symmetric algorithm
        #
        def encrypt_symmetrically(options = {})
          create_encrypted_string(SymmetricallyEncryptedString, options)
        end
        alias_method :encrypt_symmetric, :encrypt_symmetrically
        
        # Adds support for testing equality with an encrypted string
        #
        def equals_with_encryption(other)
          if EncryptedString === other
            other == self
          else
            equals_without_encryption(other)
          end
        end
        
        private
        def create_encrypted_string(klass, options) #:nodoc:
          klass.new(self, options)
        end
      end
    end
  end
end

::String.class_eval do
  include PluginAWeek::CoreExtensions::String::EncryptedStrings
end
{'fraction_non_alphanumeric': 0.07241379310344828, 'fraction_numerical': 0.0008113590263691683, 'mean_word_length': 2.3960055096418733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3709370', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1306, 'n_words': 326}