闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
402 B

  1. # frozen_string_literal: true
  2. class Ed25519KeyValidator < ActiveModel::EachValidator
  3. def validate_each(record, attribute, value)
  4. return if value.blank?
  5. key = Base64.decode64(value)
  6. record.errors[attribute] << I18n.t('crypto.errors.invalid_key') unless verified?(key)
  7. end
  8. private
  9. def verified?(key)
  10. Ed25519.validate_key_bytes(key)
  11. rescue ArgumentError
  12. false
  13. end
  14. end