Class: R509::CertificateAuthority::Http::SubjectParser

Inherits:
Object
  • Object
show all
Defined in:
lib/r509/certificateauthority/http/subjectparser.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) parse(raw, name = "subject")



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/r509/certificateauthority/http/subjectparser.rb', line 5

def parse(raw, name="subject")
    if raw.nil?
        raise ArgumentError, "Must provide a query string"
    end

    subject = R509::Subject.new
    raw.split(/[&;] */n).each { |pair|
        key, value = pair.split('=', 2).map { |data| unescape(data) }
        match = key.match(/#{name}\[(.*)\]/)
        if not match.nil? and not value.empty?
            subject[match[1]] = value
        end
    }
    subject
end

- (Object) unescape(s, encoding = Encoding::UTF_8)



22
23
24
# File 'lib/r509/certificateauthority/http/subjectparser.rb', line 22

def unescape(s, encoding = Encoding::UTF_8)
    URI.decode_www_form_component(s, encoding)
end