Class: EzCrypto::Name

Inherits:
Object show all
Defined in:
lib/extensions/ezcrypto/ezcrypto/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.


385
386
387
388
389
390
391
392
393
394
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 385

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



467
468
469
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 467

def method_missing(method)
  self[method]
end

Instance Method Details

#[](attr_key) ⇒ Object

Lookup fields in the certificate.



463
464
465
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 463

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.



454
455
456
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 454

def common_name
  self[:CN]
end

#countryObject Also known as: c

The 2 letter country code of the name



412
413
414
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 412

def country
  self[:C]
end

#emailObject

Returns the email if present in the name



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

def email
  self[:emailAddress]
end

#localityObject Also known as: l

The locality



428
429
430
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 428

def locality
  self[:L]
end

#organizationObject Also known as: o, organisation

The Organization



445
446
447
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 445

def organization
  self[:O]
end

#organizational_unitObject Also known as: ou, organisational_unit

The Organizational Unit



436
437
438
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 436

def organizational_unit
  self[:OU]
end

#stateObject Also known as: st, province

The state or province code



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

def state
  self[:ST]
end

#to_sObject

Returns the full name object in classic horrible X500 format.



399
400
401
# File 'lib/extensions/ezcrypto/ezcrypto/ezsig.rb', line 399

def to_s
  @name.to_s
end