Sha256: 4214d2e3a226aad793609b9432c8e07f4d78eba55933f12f5319319321280620

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module KPM
  module SystemProxy
    class EntropyAvailable
      attr_reader :entropy_available, :labels

      def initialize
        @entropy_available = fetch
        @labels = [{ label: :entropy },
                   { label: :value }]
      end

      private

      def fetch
        entropy_available = nil
        if OS.windows?
          entropy_available = fetch_windows
        elsif OS.linux?
          entropy_available = fetch_linux
        elsif OS.mac?
          entropy_available = fetch_mac
        end

        entropy_available
      end

      def fetch_linux
        entropy_available_data = `cat /proc/sys/kernel/random/entropy_avail 2>&1`.gsub("\n", '')
        build_hash(entropy_available_data)
      end

      def fetch_mac
        build_hash('-')
      end

      def fetch_windows
        build_hash('-')
      end

      def build_hash(data)
        entropy_available = {}
        entropy_available['entropy_available'] = { entropy: 'available', value: data }

        entropy_available
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kpm-0.10.6 lib/kpm/system_helpers/entropy_available.rb
kpm-0.11.1 lib/kpm/system_helpers/entropy_available.rb
kpm-0.10.5 lib/kpm/system_helpers/entropy_available.rb
kpm-0.11.0 lib/kpm/system_helpers/entropy_available.rb
kpm-0.10.4 lib/kpm/system_helpers/entropy_available.rb
kpm-0.10.3 lib/kpm/system_helpers/entropy_available.rb
kpm-0.10.2 lib/kpm/system_helpers/entropy_available.rb
kpm-0.10.1 lib/kpm/system_helpers/entropy_available.rb
kpm-0.10.0 lib/kpm/system_helpers/entropy_available.rb
kpm-0.9.0 lib/kpm/system_helpers/entropy_available.rb
kpm-0.8.2 lib/kpm/system_helpers/entropy_available.rb
kpm-0.8.1 lib/kpm/system_helpers/entropy_available.rb
kpm-0.8.0 lib/kpm/system_helpers/entropy_available.rb