class DKIM::Query::Key

Represents an individual DKIM signing key.

Attributes

flags[R]

`t=` tag.

@return [:y, :s, String, nil]

g[R]

`g=` tag.

@return [String, nil]

granularity[R]

`g=` tag.

@return [String, nil]

h[R]

`h=` tag.

@return [:sha1, :sha256, Array<:sha1, :sha256, String>, nil]

hash[R]

`h=` tag.

@return [:sha1, :sha256, Array<:sha1, :sha256, String>, nil]

k[R]

`k=` tag.

@return [:rsa, String]

key[R]

`k=` tag.

@return [:rsa, String]

n[R]

`n=` tag.

@return [String, nil]

notes[R]

`n=` tag.

@return [String, nil]

p[R]

`p=` tag.

@return [String, nil]

public_key[R]

`p=` tag.

@return [String, nil]

s[R]

`s=` tag.

@return [:email, :*, String, Array<:email, :*, String>, nil]

service_type[R]

`s=` tag.

@return [:email, :*, String, Array<:email, :*, String>, nil]

t[R]

`t=` tag.

@return [:y, :s, String, nil]

v[R]

DKIM version.

@return [:DKIM1]

version[R]

DKIM version.

@return [:DKIM1]

Public Class Methods

new(tags={}) click to toggle source

Initialize the key.

@param [Hash{Symbol => Symbol,String}] tags

Tags for the key.

@option tags [Symbol] :v

@option tags [Symbol] :g

@option tags [Symbol] :h

@option tags [Symbol] :k

@option tags [Symbol] :n

@option tags [Symbol] :p

@option tags [Symbol] :s

@option tags [Symbol] :t

# File lib/dkim/query/key.rb, line 82
def initialize(tags={})
  @v, @g, @h, @k, @n, @p, @s, @t = tags.values_at(:v,:g,:h,:k,:n,:p,:s,:t)
end
parse(record) click to toggle source

Parses a DKIM Key record.

@param [String] record

The DKIM key record.

@return [Key, MalformedKey]

The parsed key. If the key could not be parsed, a {MalformedKey}
will be returned.
# File lib/dkim/query/key.rb, line 114
def self.parse(record)
  begin
    parse!(record)
  rescue Parslet::ParseFailed => error
    MalformedKey.new(record,error.cause)
  end
end
parse!(record) click to toggle source

Parses a DKIM Key record.

@param [String] record

The DKIM key record.

@return [Key]

The new key.

@raise [InvalidKey]

Could not parse the DKIM Key record.
# File lib/dkim/query/key.rb, line 98
def self.parse!(record)
  new(Parser.parse(record))
rescue Parslet::ParseFailed => error
  raise(InvalidKey.new(error.message,error.cause))
end

Public Instance Methods

to_hash() click to toggle source

Converts the key to a Hash.

@return [Hash{:v,:g,:h,:k,:n,:p,:s,:t => Object}]

# File lib/dkim/query/key.rb, line 127
def to_hash
  {
    v: @v,
    g: @g,
    h: @h,
    k: @k,
    n: @n,
    p: @p,
    s: @s,
    t: @t
  }
end
to_s() click to toggle source

Converts the key back into a DKIM String.

@return [String]

# File lib/dkim/query/key.rb, line 145
def to_s
  tags = []

  tags << "v=#{@v}" if @v
  tags << "g=#{@g}" if @g
  tags << "h=#{@h}" if @h
  tags << "k=#{@k}" if @k
  tags << "p=#{@p}" if @p
  tags << "s=#{@s}" if @s
  tags << "t=#{@t}" if @t
  tags << "n=#{@n}" if @n

  return tags.join('; ')
end