Class: QuickAndRuby::DistinguishedName
- Inherits:
-
Object
- Object
- QuickAndRuby::DistinguishedName
show all
- Defined in:
- lib/quick_and_ruby/distinguished_name.rb,
lib/quick_and_ruby/distinguished_name/attribute.rb,
lib/quick_and_ruby/distinguished_name/rfc_format.rb,
lib/quick_and_ruby/distinguished_name/openssl_format.rb
Defined Under Namespace
Classes: Attribute, OpensslFormat, RfcFormat
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DistinguishedName.
11
12
13
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 11
def initialize(attributes = [])
@attributes = attributes
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9
10
11
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 9
def attributes
@attributes
end
|
Class Method Details
.from_s(dn_str, format: nil) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 34
def from_s(dn_str, format: nil)
return new if !dn_str || dn_str.empty?
formatter ||= get_format(format) if format
formatter ||= openssl_format if openssl_format.recognize?(dn_str)
formatter ||= rfc_format
attributes = formatter.split(dn_str)
new(attributes)
end
|
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 54
def get_format(label = :rfc)
case label.to_sym
when :rfc
RfcFormat.new
when :openssl
OpensslFormat.new
else
raise ArgumentError, "Unsupported format #{label}"
end
end
|
50
51
52
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 50
def openssl_format
get_format(:openssl)
end
|
46
47
48
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 46
def rfc_format
get_format(:rfc)
end
|
Instance Method Details
29
30
31
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 29
def get_format(label = :rfc)
self.class.get_format(label)
end
|
#reverse ⇒ Object
20
21
22
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 20
def reverse
self.class.new(attributes.reverse)
end
|
#size ⇒ Object
Also known as:
length
24
25
26
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 24
def size
attributes.size
end
|
#to_s(format: :rfc) ⇒ Object
15
16
17
18
|
# File 'lib/quick_and_ruby/distinguished_name.rb', line 15
def to_s(format: :rfc)
formatter = get_format(format)
formatter.join(attributes)
end
|