Class: Cryptorecord::Openpgpkeys

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptorecord/openpgpkeys.rb

Overview

Cryptorecord::Openpgpkeys-class generates openphpkeys-dns-records. Instances must have an uid. The PGP-Key can be read from file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Openpgpkeys

This constructor initializes domain, uid and key

with the pgp-key

Parameters:

  • uid (String|Mail::Address)

    email-address associated

  • key (String)

    pgp-key


41
42
43
44
# File 'lib/cryptorecord/openpgpkeys.rb', line 41

def initialize(args = {})
  self.uid = args.fetch(:uid, nil)
  self.key = args.fetch(:key, nil)
end

Instance Attribute Details

#keyObject

Returns the value of attribute key


34
# File 'lib/cryptorecord/openpgpkeys.rb', line 34

attr_reader :uid, :key

#uidObject

stores the user-id


34
35
36
# File 'lib/cryptorecord/openpgpkeys.rb', line 34

def uid
  @uid
end

Instance Method Details

#domainObject

This getter returns the domain-part of the uid(email-address) or nil


81
82
83
# File 'lib/cryptorecord/openpgpkeys.rb', line 81

def domain
  @uid.nil? ? nil : @uid.domain
end

#localpartObject

This getter returns the SHA256sum of the uid-local-part(email-address) as defined in rfc7929

uid(email-address) as SHA256 reduced to 56bytes or nil


74
75
76
# File 'lib/cryptorecord/openpgpkeys.rb', line 74

def localpart
  @uid.nil? ? nil : OpenSSL::Digest::SHA256.new(@uid.local.to_s).to_s[0..55]
end

This method prints the openpgpkey-record to stdout


129
130
131
# File 'lib/cryptorecord/openpgpkeys.rb', line 129

def print
  puts self
end

#read_gpgkeyfile(keyfile) ⇒ Object

This method reads the pgp-key from a given file

Parameters:

  • keyfile (String)

    Path to the keyfile

Raises:


122
123
124
125
126
# File 'lib/cryptorecord/openpgpkeys.rb', line 122

def read_gpgkeyfile(keyfile)
  raise Cryptorecord::ArgumentError, 'No keyfile defined' if keyfile.nil?
  data = File.read(keyfile)
  self.key = data
end

#to_sObject

This method concats the openpgpkey-record


136
137
138
# File 'lib/cryptorecord/openpgpkeys.rb', line 136

def to_s
  "#{localpart}._openpgpkey.#{domain}. IN OPENPGPKEY #{@key}"
end

#trimpgpkey(val) ⇒ Object

This function trims the pgpkey so that all headers, footers, blanklines, and stuff are gone

otherwise the line itself

Parameters:

  • val (String)

    onne line of the pgpkey-block


93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cryptorecord/openpgpkeys.rb', line 93

def trimpgpkey(val)
  case val
  when '-----BEGIN PGP PUBLIC KEY BLOCK-----'
    ''
  when  '-----END PGP PUBLIC KEY BLOCK-----'
    ''
  when  "^\s*\n$"
    ''
  else
    val.to_s
  end
end