summaryrefslogtreecommitdiff
path: root/controllers/security.rb
blob: 8f066a53b03e0103da04bbd96afd96b7006f2164 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

require_relative '../components/crypto'

module NanoBot
  module Controllers
    module Security
      def self.decrypt(content)
        Components::Crypto.decrypt(content)
      end

      def self.check
        password = ENV.fetch('NANO_BOTS_ENCRYPTION_PASSWORD', nil)
        password = 'UNSAFE' unless password && password != ''

        {
          encryption: (
            Components::Crypto.encrypt('SAFE') != 'SAFE' &&
            Components::Crypto.encrypt('SAFE') != Components::Crypto.encrypt('SAFE') &&
            Components::Crypto.decrypt(Components::Crypto.encrypt('SAFE')) == 'SAFE'
          ),
          password: password != 'UNSAFE'
        }
      end
    end
  end
end