1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-23 11:08:21 +09:00
mastodon/app/validators/web_push_key_validator.rb

12 lines
372 B
Ruby
Raw Normal View History

# 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