1
0
Fork 0
This repository has been archived on 2023-03-28. 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

# frozen_string_literal: true
class X509Certificate < ApplicationRecord
################
# Associations #
################
belongs_to :asymmetric_key
###############
# 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
end