Class: QuickAndRuby::DistinguishedName::OpensslFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/quick_and_ruby/distinguished_name/openssl_format.rb

Constant Summary collapse

LABEL =
:openssl
SEPARATOR =
'/'
SPLIT_RE =
%r{(?<!\\)/}.freeze

Instance Method Summary collapse

Instance Method Details

#escape(value) ⇒ Object



12
13
14
# File 'lib/quick_and_ruby/distinguished_name/openssl_format.rb', line 12

def escape(value)
  value.gsub(%r{([/\\])}, '\\\\\1')
end

#join(attributes) ⇒ Object



39
40
41
42
43
# File 'lib/quick_and_ruby/distinguished_name/openssl_format.rb', line 39

def join(attributes)
  SEPARATOR + attributes.map do |attribute|
    attribute.to_s(escaper: method(:escape))
  end.join(SEPARATOR)
end

#recognize?(dn_str) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/quick_and_ruby/distinguished_name/openssl_format.rb', line 20

def recognize?(dn_str)
  return true if !dn_str || dn_str.empty?
  return true if dn_str.start_with?(SEPARATOR)

  false
end

#split(dn_str) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/quick_and_ruby/distinguished_name/openssl_format.rb', line 27

def split(dn_str)
  dn_str = dn_str[1..] if dn_str.start_with?(SEPARATOR)

  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



16
17
18
# File 'lib/quick_and_ruby/distinguished_name/openssl_format.rb', line 16

def unescape(value)
  value.gsub(%r{\\([/\\])}, '\1')
end