blob: 71d69cf569466d430856b6c2873645cde7ea52ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#
# str_and_salt2sha1.rb
#
module Puppet::Parser::Functions
newfunction(:str_and_salt2sha1, :type => :rvalue, :doc => <<-EOS
This converts a string to an array containing the salted SHA1 password hash in
the first field, and the salt itself in second field of the returned array.
This combination is used i.e. for couchdb passwords.
EOS
) do |arguments|
require 'digest/sha1'
raise(Puppet::ParseError, "str_and_salt2sha1(): Wrong number of arguments " +
"passed (#{arguments.size} but we require 1)") if arguments.size != 1
str_and_salt = arguments[0]
unless str_and_salt.is_a?(Array)
raise(Puppet::ParseError, 'str_and_salt2sha1(): Requires a ' +
"Array argument, you passed: #{password.class}")
end
str = str_and_salt[0]
salt = str_and_salt[1]
sha1 = Digest::SHA1.hexdigest(str+ salt)
return sha1
end
end
# vim: set ts=2 sw=2 et :
|