Class: QuickAndRuby::DistinguishedName::RfcFormat
- Inherits:
-
Object
- Object
- QuickAndRuby::DistinguishedName::RfcFormat
- Defined in:
- lib/quick_and_ruby/distinguished_name/rfc_format.rb
Constant Summary collapse
- LABEL =
:rfc- SEPARATOR =
','- SPLIT_RE =
/(?<!\\),/.freeze
- UNESCAPE_ALL_RE =
/\\(.)/.freeze
Instance Method Summary collapse
- #escape(value) ⇒ Object
- #join(attributes) ⇒ Object
- #recognize?(dn_str) ⇒ Boolean
- #split(dn_str) ⇒ Object
- #unescape(value) ⇒ Object
Instance Method Details
#escape(value) ⇒ Object
14 15 16 17 |
# File 'lib/quick_and_ruby/distinguished_name/rfc_format.rb', line 14 def escape(value) # value.gsub(/([,\\+<>;"= ])/, '\\\1') value.gsub(/([,\\+<>;"=])/, '\\\\\1') end |
#join(attributes) ⇒ Object
40 41 42 43 44 |
# File 'lib/quick_and_ruby/distinguished_name/rfc_format.rb', line 40 def join(attributes) attributes.map do |attribute| attribute.to_s(escaper: method(:escape)) end.join(SEPARATOR) end |
#recognize?(dn_str) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/quick_and_ruby/distinguished_name/rfc_format.rb', line 24 def recognize?(dn_str) return true if !dn_str || dn_str.empty? true end |
#split(dn_str) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/quick_and_ruby/distinguished_name/rfc_format.rb', line 30 def split(dn_str) parts = dn_str.split(SPLIT_RE) parts.map do |part| part = part.strip if part next if !part || part.empty? Attribute.from_s(part, unescaper: method(:unescape)) end.compact end |
#unescape(value) ⇒ Object
19 20 21 22 |
# File 'lib/quick_and_ruby/distinguished_name/rfc_format.rb', line 19 def unescape(value) # .gsub(UNESCAPE_ALL_RE, '\1') value.gsub(/\\([,\\+<>;"= ])/, '\1') end |