Class: R509::Subject
- Inherits:
-
Object
- Object
- R509::Subject
- Defined in:
- lib/r509/subject.rb
Overview
subject class. Used for building OpenSSL::X509::Name objects in a sane fashion
Instance Method Summary (collapse)
-
- (Object) [](key)
get value for key.
-
- (Object) []=(key, value)
set key and value.
- - (Object) delete(key)
- - (Boolean) empty?
-
- (Subject) initialize(arg = nil)
constructor
A new instance of Subject.
- - (OpenSSL::X509::Name) name
-
- (Array) to_a
Array of form [['CN','langui.sh'],].
-
- (String) to_s
String of form /CN=something.com/O=whatever/L=Locality.
Constructor Details
- (Subject) initialize(arg = nil)
A new instance of Subject
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/r509/subject.rb', line 7 def initialize(arg=nil) case arg when Array @array = arg when OpenSSL::X509::Name sanitizer = R509::NameSanitizer.new @array = sanitizer.sanitize(arg) when R509::Subject @array = arg.to_a else @array = [] end # see if X509 thinks this is okay name end |
Instance Method Details
- (Object) [](key)
get value for key
35 36 37 38 39 40 41 42 |
# File 'lib/r509/subject.rb', line 35 def [](key) @array.each do |item| if key == item[0] return item[1] end end return nil end |
- (Object) []=(key, value)
set key and value
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/r509/subject.rb', line 45 def []=(key, value) added = false @array = @array.map{ |item| if key == item[0] added = true [key, value] else item end } if not added @array << [key, value] end # see if X509 thinks this is okay name @array end |
- (Object) delete(key)
67 68 69 70 71 |
# File 'lib/r509/subject.rb', line 67 def delete(key) @array = @array.select do |item| item[0] != key end end |
- (Boolean) empty?
30 31 32 |
# File 'lib/r509/subject.rb', line 30 def empty? @array.empty? end |
- (OpenSSL::X509::Name) name
25 26 27 |
# File 'lib/r509/subject.rb', line 25 def name OpenSSL::X509::Name.new(@array) end |
- (Array) to_a
Array of form [['CN','langui.sh'],]
79 80 81 |
# File 'lib/r509/subject.rb', line 79 def to_a @array end |
- (String) to_s
String of form /CN=something.com/O=whatever/L=Locality
74 75 76 |
# File 'lib/r509/subject.rb', line 74 def to_s name.to_s end |