Source

chitin / lib / chitin / manifests / manifest.rb

require 'openssl'

module Chitin
  class Manifest

    def self.register(hash)
      @@password_hash = hash
    end

    # retrieve the manifest entry for the name
    def self.find(name)
      manifest_path = File.expand_path '.chitin_manifest'
      manifest      = File.read manifest_path
      manifest_hmac = manifest_data[0..511]
      manifest_data = manifest_data[512..-1]

      # verify the authenticity of the file
      computed_hmac = OpenSSL::HMAC.hexdigest('sha256',
                                              @@password_hash,
                                              manifest_data)

      unless computed_hmac == manifest_hmac
        puts "MANIFEST FILE HAS BEEN TAMPERED WITH"
        return {}
      end

      @@data ||= {}
      @@data[manifest_path] ||= YAML.load manifest_data
      @@data[manifest_path][name]
    end

    def initialize
    end
  end
end