~ubuntu-branches/ubuntu/karmic/chef/karmic

« back to all changes in this revision

Viewing changes to chef/lib/chef/mixin/checksum.rb

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Timberman
  • Date: 2009-08-12 12:18:48 UTC
  • Revision ID: james.westby@ubuntu.com-20090812121848-yl38hpd7nfsl51xz
Tags: upstream-0.7.8
ImportĀ upstreamĀ versionĀ 0.7.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Author:: Adam Jacob (<adam@opscode.com>)
 
3
# Copyright:: Copyright (c) 2008 Opscode, Inc.
 
4
# License:: Apache License, Version 2.0
 
5
#
 
6
# Licensed under the Apache License, Version 2.0 (the "License");
 
7
# you may not use this file except in compliance with the License.
 
8
# You may obtain a copy of the License at
 
9
 
10
#     http://www.apache.org/licenses/LICENSE-2.0
 
11
 
12
# Unless required by applicable law or agreed to in writing, software
 
13
# distributed under the License is distributed on an "AS IS" BASIS,
 
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
# See the License for the specific language governing permissions and
 
16
# limitations under the License.
 
17
#
 
18
 
 
19
require 'digest/sha2'
 
20
 
 
21
class Chef
 
22
  module Mixin
 
23
    module Checksum
 
24
 
 
25
      def checksum(file)
 
26
        digest = Digest::SHA256.new
 
27
        fh = ::File.open(file)
 
28
        fh.each do |line|
 
29
          digest.update(line)
 
30
        end
 
31
        fh.close
 
32
        digest.hexdigest
 
33
      end
 
34
      
 
35
    end
 
36
  end
 
37
end