Class: EzCrypto::Name

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

Overview

A handy ruby wrapper around OpenSSL’s Name object. This was created to make it really easy to extract information out of the certificate.

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Name

Initializes the Name object with the underlying OpenSSL Name object. You generally do not need to use this.

Rather use the Certificates subject or issuer methods.


337
338
339
340
341
342
343
344
345
346
# File 'lib/ezsig.rb', line 337

def initialize(name)
  @name=name
  @attributes={}
  name.to_s.split(/\//).each do |field| 
    key, val = field.split(/=/,2)
    if key
      @attributes[key.to_sym]=val
    end
  end  
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



419
420
421
# File 'lib/ezsig.rb', line 419

def method_missing(method)
  self[method]
end

Instance Method Details

#[](attr_key) ⇒ Object

Lookup fields in the certificate.



415
416
417
# File 'lib/ezsig.rb', line 415

def [](attr_key)
  @attributes[attr_key.to_sym]
end

#common_nameObject Also known as: name, cn

The common name. For SSL this means the domain name. For personal certificates it is the name.



406
407
408
# File 'lib/ezsig.rb', line 406

def common_name
  self[:CN]
end

#countryObject Also known as: c

The 2 letter country code of the name



364
365
366
# File 'lib/ezsig.rb', line 364

def country
  self[:C]
end

#emailObject

Returns the email if present in the name



358
359
360
# File 'lib/ezsig.rb', line 358

def email
  self[:emailAddress]
end

#localityObject Also known as: l

The locality



380
381
382
# File 'lib/ezsig.rb', line 380

def locality
  self[:L]
end

#organizationObject Also known as: o, organisation

The Organization



397
398
399
# File 'lib/ezsig.rb', line 397

def organization
  self[:O]
end

#organizational_unitObject Also known as: ou, organisational_unit

The Organizational Unit



388
389
390
# File 'lib/ezsig.rb', line 388

def organizational_unit
  self[:OU]
end

#stateObject Also known as: st, province

The state or province code



371
372
373
# File 'lib/ezsig.rb', line 371

def state
  self[:ST]
end

#to_sObject

Returns the full name object in classic horrible X500 format.



351
352
353
# File 'lib/ezsig.rb', line 351

def to_s
  @name.to_s
end