class RubyGPG2::ColonRecord
Constants
- COMPLIANCE_MODES
- KEY_ALGORITHMS
- KEY_CAPABILITIES
- TRUSTS
- TRUST_MODELS
- TYPES
- USER_ID_REGEX
- VALIDITIES
Attributes
compliance_modes[R]
creation_date[R]
expiration_date[R]
fingerprint[R]
key_algorithm[R]
key_capabilities[R]
key_grip[R]
key_id[R]
key_length[R]
last_update[R]
maximum_certificate_chain_depth[R]
new_key_signer_complete_count[R]
new_key_signer_marginal_count[R]
origin[R]
owner_trust[R]
raw[R]
serial_number[R]
signature_class[R]
trust_model[R]
type[R]
user_id[R]
user_id_hash[R]
validity[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 152 def initialize(opts) @raw = opts[:raw] @type = opts[:type] @trust_model = opts[:trust_model] @validity = opts[:validity] @key_length = opts[:key_length] @key_algorithm = opts[:key_algorithm] @key_id = opts[:key_id] @creation_date = opts[:creation_date] @expiration_date = opts[:expiration_date] @user_id_hash = opts[:user_id_hash] @owner_trust = opts[:owner_trust] @fingerprint = opts[:fingerprint] @key_grip = opts[:key_grip] @user_id = opts[:user_id] @signature_class = opts[:signature_class] @key_capabilities = opts[:key_capabilities] @serial_number = opts[:serial_number] @compliance_modes = opts[:compliance_modes] @last_update = opts[:last_update] @origin = opts[:origin] @new_key_signer_marginal_count = opts[:new_key_signer_marginal_count] @new_key_signer_complete_count = opts[:new_key_signer_complete_count] @maximum_certificate_chain_depth = opts[:maximum_certificate_chain_depth] end
parse(record)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 86 def self.parse(record) fields = record.split(':', 22) type = type(fields[0]) case type when :trust_database_information new( raw: record, type: type, trust_model: trust_model(fields[2]), creation_date: creation_date(fields[3]), expiration_date: expiration_date(fields[4]), new_key_signer_marginal_count: new_key_signer_marginal_count(fields[5]), new_key_signer_complete_count: new_key_signer_complete_count(fields[6]), maximum_certificate_chain_depth: maximum_certificate_chain_depth(fields[7])) else new( raw: record, type: type, validity: validity(fields[1]), key_length: key_length(fields[2]), key_algorithm: key_algorithm(fields[3]), key_id: key_id(fields[4]), creation_date: creation_date(fields[5]), expiration_date: expiration_date(fields[6]), user_id_hash: user_id_hash(type, fields[7]), owner_trust: owner_trust(fields[8]), fingerprint: fingerprint(type, fields[9]), key_grip: key_grip(type, fields[9]), user_id: user_id(type, fields[9]), signature_class: signature_class(fields[10]), key_capabilities: key_capabilities(fields[11]), serial_number: serial_number(fields[14]), compliance_modes: compliance_modes(fields[17]), last_update: last_update(fields[18]), origin: origin(fields[19])) end end
Private Class Methods
compliance_modes(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 306 def self.compliance_modes(value) value =~ /.+/ ? value.split(' ').map { |m| COMPLIANCE_MODES[m] } : nil end
creation_date(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 264 def self.creation_date(value) value =~ /\d+/ ? DateTime.strptime(value, '%s') : nil end
expiration_date(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 268 def self.expiration_date(value) value =~ /\d+/ ? DateTime.strptime(value, '%s') : nil end
fingerprint(type, value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 280 def self.fingerprint(type, value) type == :fingerprint ? value : nil end
key_algorithm(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 256 def self.key_algorithm(value) KEY_ALGORITHMS[value] end
key_capabilities(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 298 def self.key_capabilities(value) value =~ /.+/ ? value.chars.map { |c| KEY_CAPABILITIES[c] } : nil end
key_grip(type, value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 284 def self.key_grip(type, value) type == :key_grip ? value : nil end
key_id(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 260 def self.key_id(value) value =~ /.+/ ? value : nil end
key_length(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 252 def self.key_length(value) value =~ /\d+/ ? value.to_s.to_i : nil end
last_update(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 310 def self.last_update(value) value =~ /\d+/ ? DateTime.strptime(value, '%s') : nil end
maximum_certificate_chain_depth(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 326 def self.maximum_certificate_chain_depth(value) value =~ /\d+/ ? value.to_i : nil end
new_key_signer_complete_count(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 322 def self.new_key_signer_complete_count(value) value =~ /\d+/ ? value.to_i : nil end
new_key_signer_marginal_count(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 318 def self.new_key_signer_marginal_count(value) value =~ /\d+/ ? value.to_i : nil end
origin(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 314 def self.origin(value) value end
owner_trust(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 276 def self.owner_trust(value) TRUSTS[value] end
serial_number(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 302 def self.serial_number(value) value =~ /.+/ ? value : nil end
signature_class(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 294 def self.signature_class(value) value =~ /.+/ ? value : nil end
trust_model(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 244 def self.trust_model(value) TRUST_MODELS[value] end
type(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 240 def self.type(value) TYPES[value] end
user_id(type, value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 288 def self.user_id(type, value) unless [:fingerprint, :key_grip].include?(type) value =~ /.+/ ? value : nil end end
user_id_hash(type, value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 272 def self.user_id_hash(type, value) type == :user_id ? value : nil end
validity(value)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 248 def self.validity(value) VALIDITIES[value] end
Public Instance Methods
==(other)
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 204 def ==(other) other.class == self.class && other.state == state end
fingerprint_record?()
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 178 def fingerprint_record? type == :fingerprint end
user_comment()
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 192 def user_comment if (match = user_id&.match(USER_ID_REGEX)) match[2] end end
user_email()
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 198 def user_email if (match = user_id&.match(USER_ID_REGEX)) match[3] end end
user_id_record?()
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 182 def user_id_record? type == :user_id end
user_name()
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 186 def user_name if (match = user_id&.match(USER_ID_REGEX)) match[1] end end
Protected Instance Methods
state()
click to toggle source
# File lib/ruby_gpg2/colon_record.rb, line 210 def state [ @raw, @type, @trust_model, @validity, @key_length, @key_algorithm, @key_id, @creation_date, @expiration_date, @user_id_hash, @owner_trust, @fingerprint, @key_grip, @user_id, @signature_class, @key_capabilities, @serial_number, @compliance_modes, @last_update, @origin, @new_key_signer_marginal_count, @new_key_signer_complete_count, @maximum_certificate_chain_depth ] end