ed25519_key_validator.rb 404 B

12345678910111213141516171819
  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.add(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