Puppet Function: stdlib::crc32
- Defined in:
- vendor_modules/stdlib/lib/puppet/functions/stdlib/crc32.rb
- Function type:
- Ruby 4.x API
Summary
Run a CRC32 calculation against a given value.Overview
Note:
The CRC32 algorithm can easily generate collisions, but may be useful for generating sharding, describing secrets, or seeding nonce values.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'vendor_modules/stdlib/lib/puppet/functions/stdlib/crc32.rb', line 11 Puppet::Functions.create_function(:'stdlib::crc32') do # @param my_data The ScalarData to evaluate # @example Check a simple string value # stdlib::crc32('my string') == '18fbd270' # @example Check a Sensitive datatype # stdlib::crc32(sensitive('my string')) == '18fbd270' # @example Check a number # stdlib::crc32(100.0) == 'a3fd429a' # stdlib::crc32(100.00000) == 'a3fd429a' # @return String dispatch :crc32 do param 'Variant[ScalarData, Sensitive[ScalarData], Binary, Sensitive[Binary]]', :my_data return_type 'String' end def crc32(my_data) Zlib.crc32(my_data.unwrap.to_s).to_s(16).downcase rescue Zlib.crc32(my_data.to_s).to_s(16).downcase end end |