Module: Invoance::Validate Private
- Defined in:
- lib/invoance/validate.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Shared client-side input validators.
Constant Summary collapse
- HEX_SHA256 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A[0-9a-f]{64}\z/.freeze
Class Method Summary collapse
-
.assert_sha256_hex(field_name, value) ⇒ void
private
Validate that a value is a 64-char lowercase hex SHA-256 digest.
Class Method Details
.assert_sha256_hex(field_name, value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validate that a value is a 64-char lowercase hex SHA-256 digest. Raises Invoance::ValidationError with a helpful message otherwise.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/invoance/validate.rb', line 17 def self.assert_sha256_hex(field_name, value) unless value.is_a?(String) raise ValidationError, "#{field_name} must be a string containing a 64-char hex SHA-256 digest " \ "(got #{value.class})" end if value.length != 64 raise ValidationError, "#{field_name} must be 64 hex chars (got #{value.length} chars)" end unless HEX_SHA256.match?(value) raise ValidationError, "#{field_name} must be lowercase hex [0-9a-f]; \"#{value[0, 16]}…\" is not" end end |