web_push_key_validator.rb 372 B

1234567891011
  1. # frozen_string_literal: true
  2. class WebPushKeyValidator < ActiveModel::Validator
  3. def validate(subscription)
  4. begin
  5. Webpush::Encryption.encrypt('validation_test', subscription.key_p256dh, subscription.key_auth)
  6. rescue ArgumentError, OpenSSL::PKey::EC::Point::Error
  7. subscription.errors.add(:base, I18n.t('crypto.errors.invalid_key'))
  8. end
  9. end
  10. end