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

Returns:

  • (Symbol)

    error key



14
15
16
# File 'lib/diaspora_federation/validators/rules/public_key.rb', line 14

def error_key
  :public_key
end

#paramsHash

This rule has no params.

Returns:

  • (Hash)

    params



30
31
32
# File 'lib/diaspora_federation/validators/rules/public_key.rb', line 30

def params
  {}
end

#valid_value?(value) ⇒ Boolean

Determines if value is a valid public key

Returns:



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

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