Puppet Function: stdlib::sha256

Defined in:
vendor_modules/stdlib/lib/puppet/functions/stdlib/sha256.rb
Function type:
Ruby 4.x API

Summary

Run a SHA256 calculation against a given value.

Overview

stdlib::sha256(Variant[ScalarData, Sensitive[ScalarData], Binary, Sensitive[Binary]] $my_data)String

Examples:

Check a simple string value

stdlib::sha256('my string') == '2f7e2089add0288a309abd71ffcc3b3567e2d4215e20e6ed3b74d6042f7ef8e5'

Check a Sensitive datatype

stdlib::sha256(sensitive('my string')) == '2f7e2089add0288a309abd71ffcc3b3567e2d4215e20e6ed3b74d6042f7ef8e5'

Check a number

stdlib::sha256(100.0) == '43b87f618caab482ebe4976c92bcd6ad308b48055f1c27b4c574f3e31d7683e0'
stdlib::sha256(100.00000) == '43b87f618caab482ebe4976c92bcd6ad308b48055f1c27b4c574f3e31d7683e0'

Parameters:

  • my_data (Variant[ScalarData, Sensitive[ScalarData], Binary, Sensitive[Binary]])

    The ScalarData to evaluate

Returns:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'vendor_modules/stdlib/lib/puppet/functions/stdlib/sha256.rb', line 6

Puppet::Functions.create_function(:'stdlib::sha256') do
  # @param my_data The ScalarData to evaluate
  # @example Check a simple string value
  #   stdlib::sha256('my string') == '2f7e2089add0288a309abd71ffcc3b3567e2d4215e20e6ed3b74d6042f7ef8e5'
  # @example Check a Sensitive datatype
  #   stdlib::sha256(sensitive('my string')) == '2f7e2089add0288a309abd71ffcc3b3567e2d4215e20e6ed3b74d6042f7ef8e5'
  # @example Check a number
  #   stdlib::sha256(100.0) == '43b87f618caab482ebe4976c92bcd6ad308b48055f1c27b4c574f3e31d7683e0'
  #   stdlib::sha256(100.00000) == '43b87f618caab482ebe4976c92bcd6ad308b48055f1c27b4c574f3e31d7683e0'
  # @return String
  dispatch :sha256 do
    param 'Variant[ScalarData, Sensitive[ScalarData], Binary, Sensitive[Binary]]', :my_data
    return_type 'String'
  end

  def sha256(my_data)
    Digest::SHA256.hexdigest(my_data.unwrap.to_s)
  rescue
    Digest::SHA256.hexdigest(my_data.to_s)
  end
end