mastodon/app/validators/web_push_key_validator.rb
S1m 4a2813158d
Add support for standard webpush (#33528)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
2025-01-14 09:14:00 +00:00

12 lines
372 B
Ruby

# frozen_string_literal: true
class WebPushKeyValidator < ActiveModel::Validator
def validate(subscription)
begin
Webpush::Encryption.encrypt('validation_test', subscription.key_p256dh, subscription.key_auth)
rescue ArgumentError, OpenSSL::PKey::EC::Point::Error
subscription.errors.add(:base, I18n.t('crypto.errors.invalid_key'))
end
end
end