Class: Validation::Rule::PublicKey

Inherits:
Object
  • Object
show all
Defined in:
lib/diaspora_federation/validators/rules/public_key.rb

Overview

Public key validation rule

A valid key must:

  • start with “—–BEGIN PUBLIC KEY—–” and end with “—–END PUBLIC KEY—–”

or

  • start with “—–BEGIN RSA PUBLIC KEY—–” and end with “—–END RSA PUBLIC KEY—–”

Instance Method Summary collapse

Instance Method Details

#error_keySymbol

The error key for this rule


12
13
14
# File 'lib/diaspora_federation/validators/rules/public_key.rb', line 12

def error_key
  :public_key
end

#paramsHash

This rule has no params.


28
29
30
# File 'lib/diaspora_federation/validators/rules/public_key.rb', line 28

def params
  {}
end

#valid_value?(value) ⇒ Boolean

Determines if value is a valid public key


17
18
19
20
21
22
23
24
# File 'lib/diaspora_federation/validators/rules/public_key.rb', line 17

def valid_value?(value)
  !value.nil? && (
    (value.strip.start_with?("-----BEGIN PUBLIC KEY-----") &&
     value.strip.end_with?("-----END PUBLIC KEY-----")) ||
    (value.strip.start_with?("-----BEGIN RSA PUBLIC KEY-----") &&
      value.strip.end_with?("-----END RSA PUBLIC KEY-----"))
  )
end