mobiledefense/google_safe_browsing

View on GitHub
lib/google_safe_browsing/hash_helper.rb

Summary

Maintainability
A
0 mins
Test Coverage
module GoogleSafeBrowsing
  class HashHelper

    class GsbHash
      def initialize(hash)
        @hash = hash
      end

      def prefix
        @hash[0..7]
      end

      def to_s
        @hash
      end

    end

    def self.urls_to_hashes(urls)
      hashes = []
      urls.each do |u|
        hash = ( Digest::SHA256.new << u ).to_s
        hashes << GsbHash.new(hash)
      end
      hashes
    end
  end
end