Module: Ace::Hitl::Hermes::Atoms::HermesTokens
- Defined in:
- lib/ace/hitl/hermes/atoms/hermes_tokens.rb
Overview
Token validation for every value that becomes part of a file name or an address (spec 8wm.t.vs1 §2): ids, senders, channel names, machine names. Path-traversal safe: no separators, no leading dot, bounded length.
Constant Summary collapse
- PATTERN =
/\A[A-Za-z0-9][A-Za-z0-9._:-]{0,63}\z/
Class Method Summary collapse
- .valid?(value) ⇒ Boolean
-
.validate!(value, label) ⇒ Object
Fail closed: raises ContractError naming the label and the rule.
Class Method Details
.valid?(value) ⇒ Boolean
16 17 18 |
# File 'lib/ace/hitl/hermes/atoms/hermes_tokens.rb', line 16 def valid?(value) value.is_a?(String) && value.match?(PATTERN) end |
.validate!(value, label) ⇒ Object
Fail closed: raises ContractError naming the label and the rule.
21 22 23 24 25 26 27 28 29 |
# File 'lib/ace/hitl/hermes/atoms/hermes_tokens.rb', line 21 def validate!(value, label) token = value.is_a?(String) ? value.strip : value return token if valid?(token) raise ContractError, "hermes #{label} must match #{PATTERN.inspect} " \ "(1..64 chars; letters, digits, '.', '_', ':', '-'; " \ "no leading dot; got #{value.inspect})" end |