Sha256: 211c549a0db4575ca0d5224b8a16537f76038c376eb9276ebd99362aa587a68d

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'rupert/rpm/signature/index'

module Rupert
  class RPM
    class Signature
      # Tag holding 128-bit MD5 checksum of header and payload
      MD5_TAG = 1004.freeze

      # Creates a new signature given its components.
      #
      # @param index [Rupert::RPM::Signature::Index] the signature index
      #              containing actual signature data
      def initialize(index)
        @index = index
      end

      # MD5 checksum contained in the RPM.
      #
      # @return [String] 128-bit MD5 checksum of RPM's header and payload, in
      #         raw binary form.
      def md5
        @index.get MD5_TAG
      end

      # Verifies if stored MD5 checksum corresponds to digest calculated over
      # given content.
      #
      # @return `true` if stored MD5 checksum corresponds to MD5 calculated
      #         over given content, `false` otherwise
      def verify_checksum(content)
        md5 == md5_checksum(content)
      end

      private

      # :nodoc
      # MD5 checksum of given string
      def md5_checksum(str)
        Digest::MD5.digest(str)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rupert-0.0.1 lib/rupert/rpm/signature.rb