Class: R509::Cert::Validator
- Inherits:
-
Object
- Object
- R509::Cert::Validator
- Defined in:
- lib/r509/cert/validator.rb,
lib/r509/cert/validator/errors.rb,
lib/r509/cert/validator/version.rb,
lib/r509/cert/validator/crl_validator.rb,
lib/r509/cert/validator/ocsp_validator.rb,
lib/r509/cert/validator/basic_validator.rb
Defined Under Namespace
Classes: BasicValidator, CrlError, CrlValidator, Error, OcspError, OcspValidator
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#cert ⇒ Object
readonly
The certificate this Validator will validate.
Instance Method Summary collapse
-
#initialize(cert, issuer = nil, options = {}) ⇒ Validator
constructor
A new instance of Validator.
- #validate(options = {}) ⇒ Object
- #validate!(options = {}) ⇒ Object
Constructor Details
#initialize(cert, issuer = nil, options = {}) ⇒ Validator
Returns a new instance of Validator.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/r509/cert/validator.rb', line 12 def initialize(cert, issuer = nil, = {}) if cert.is_a? OpenSSL::X509::Certificate cert = R509::Cert.new cert: cert end if issuer.is_a? OpenSSL::X509::Certificate issuer = R509::Cert.new cert: issuer end @cert = cert @issuer = issuer initialize_validators end |
Instance Attribute Details
#cert ⇒ Object (readonly)
The certificate this Validator will validate
10 11 12 |
# File 'lib/r509/cert/validator.rb', line 10 def cert @cert end |
Instance Method Details
#validate(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/r509/cert/validator.rb', line 47 def validate(={}) begin validate! rescue OcspError return false rescue CrlError return false end return true end |
#validate!(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/r509/cert/validator.rb', line 27 def validate!(={}) opts = { ocsp: @ocsp.available?, crl: @crl.available? }.merge if opts[:ocsp] && !@ocsp.available? raise Error.new "Tried to validate OCSP but cert has no OCSP data" end crl_file = opts[:crl_file] crl_available = @crl.available? || (crl_file && File.exist?(crl_file)) if opts[:crl] && !crl_available raise Error.new "Tried to validate CRL but cert has no CRL data" end @ocsp.validate! if opts[:ocsp] @crl.validate!(crl_file) if opts[:crl] true end |