Class: R509::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/r509/subject.rb

Overview

subject class. Used for building OpenSSL::X509::Name objects in a sane fashion

Instance Method Summary (collapse)

Constructor Details

- (Subject) initialize(arg = nil)

A new instance of Subject

Parameters:

  • arg (Array, OpenSSL::X509::Name, R509::Subject) (defaults to: nil)


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)

Parameters:

  • key (String)

    item you want deleted



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?

Returns:

  • (Boolean)


30
31
32
# File 'lib/r509/subject.rb', line 30

def empty?
    @array.empty?
end

- (OpenSSL::X509::Name) name

Returns:

  • (OpenSSL::X509::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'],]

Returns:



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

Returns:

  • (String)

    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