1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/x509_certificate.rb

34 lines
618 B
Ruby
Raw Normal View History

2019-09-10 18:57:12 -04:00
# frozen_string_literal: true
class X509Certificate < ApplicationRecord
################
# Associations #
################
2019-09-13 14:03:33 -04:00
belongs_to :asymmetric_key
2019-09-10 18:57:12 -04:00
###############
# Validations #
###############
validates :pem, presence: true
validates :subject, presence: true
validates :issuer, presence: true
validates :not_before, presence: true
validates :not_after, presence: true
validate :can_be_parsed_and_exported_with_openssl
private
def can_be_parsed_and_exported_with_openssl
OpenSSL::X509::Certificate.new(pem)&.to_text if pem.present?
rescue
errors.add :pem
end
2019-09-10 18:57:12 -04:00
end