Class: RubyGPG2::ColonRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_gpg2/colon_record.rb

Constant Summary collapse

USER_ID_REGEX =
/^(.*?) (?:\((.*)\) )?<(.*)>$/
TYPES =
{
    'pub' => :public_key,
    'crt' => :x509_certificate,
    'crs' => :x509_certificate_and_private_key,
    'sub' => :sub_key,
    'sec' => :secret_key,
    'ssb' => :secret_sub_key,
    'uid' => :user_id,
    'uat' => :user_attribute,
    'sig' => :signature,
    'rev' => :revocation_signature,
    'rvs' => :standalone_revocation_signature,
    'fpr' => :fingerprint,
    'pkd' => :public_key_data,
    'grp' => :key_grip,
    'rvk' => :revocation_key,
    'tfs' => :tofu_statistics,
    'tru' => :trust_database_information,
    'spk' => :signature_sub_packet,
    'cfg' => :configuration_data
}
TRUST_MODELS =
{
    '0' => :classic,
    '1' => :pgp
}
VALIDITIES =
{
    'o' => :unknown_new_key,
    'i' => :invalid,
    'd' => :disabled,
    'r' => :revoked,
    'e' => :expired,
    '-' => :unknown,
    'q' => :undefined,
    'n' => :never,
    'm' => :marginal,
    'f' => :full,
    'u' => :ultimate,
    'w' => :well_known_private,
    's' => :special
}
KEY_ALGORITHMS =
{
    '1' => :rsa_encrypt_or_sign,
    '2' => :rsa_encrypt_only,
    '3' => :rsa_sign_only,
    '16' => :elgamal_encrypt_only,
    '17' => :dsa,
    '18' => :ecdh,
    '19' => :ecdsa,
}
TRUSTS =
{
    '-' => :unknown,
    'n' => :never,
    'm' => :marginal,
    'f' => :full,
    'u' => :ultimate,
}
KEY_CAPABILITIES =
{
    'e' => :encrypt,
    's' => :sign,
    'c' => :certify,
    'a' => :authenticate,
    'E' => :primary_encrypt,
    'S' => :primary_sign,
    'C' => :primary_certify,
    'A' => :primary_authenticate,
    '?' => :unknown
}
COMPLIANCE_MODES =
{
    '8' => :rfc_4880bis,
    '23' => :de_vs,
    '6001' => :roca_screening_hit
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ColonRecord

Returns a new instance of ColonRecord.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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

Instance Attribute Details

#compliance_modesObject (readonly)

Returns the value of attribute compliance_modes.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def compliance_modes
  @compliance_modes
end

#creation_dateObject (readonly)

Returns the value of attribute creation_date.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def creation_date
  @creation_date
end

#expiration_dateObject (readonly)

Returns the value of attribute expiration_date.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def expiration_date
  @expiration_date
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def fingerprint
  @fingerprint
end

#key_algorithmObject (readonly)

Returns the value of attribute key_algorithm.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def key_algorithm
  @key_algorithm
end

#key_capabilitiesObject (readonly)

Returns the value of attribute key_capabilities.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def key_capabilities
  @key_capabilities
end

#key_gripObject (readonly)

Returns the value of attribute key_grip.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def key_grip
  @key_grip
end

#key_idObject (readonly)

Returns the value of attribute key_id.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def key_id
  @key_id
end

#key_lengthObject (readonly)

Returns the value of attribute key_length.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def key_length
  @key_length
end

#last_updateObject (readonly)

Returns the value of attribute last_update.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def last_update
  @last_update
end

#maximum_certificate_chain_depthObject (readonly)

Returns the value of attribute maximum_certificate_chain_depth.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def maximum_certificate_chain_depth
  @maximum_certificate_chain_depth
end

#new_key_signer_complete_countObject (readonly)

Returns the value of attribute new_key_signer_complete_count.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def new_key_signer_complete_count
  @new_key_signer_complete_count
end

#new_key_signer_marginal_countObject (readonly)

Returns the value of attribute new_key_signer_marginal_count.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def new_key_signer_marginal_count
  @new_key_signer_marginal_count
end

#originObject (readonly)

Returns the value of attribute origin.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def origin
  @origin
end

#owner_trustObject (readonly)

Returns the value of attribute owner_trust.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def owner_trust
  @owner_trust
end

#rawObject (readonly)

Returns the value of attribute raw.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def raw
  @raw
end

#serial_numberObject (readonly)

Returns the value of attribute serial_number.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def serial_number
  @serial_number
end

#signature_classObject (readonly)

Returns the value of attribute signature_class.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def signature_class
  @signature_class
end

#trust_modelObject (readonly)

Returns the value of attribute trust_model.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def trust_model
  @trust_model
end

#typeObject (readonly)

Returns the value of attribute type.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def type
  @type
end

#user_idObject (readonly)

Returns the value of attribute user_id.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def user_id
  @user_id
end

#user_id_hashObject (readonly)

Returns the value of attribute user_id_hash.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def user_id_hash
  @user_id_hash
end

#validityObject (readonly)

Returns the value of attribute validity.



127
128
129
# File 'lib/ruby_gpg2/colon_record.rb', line 127

def validity
  @validity
end

Class Method Details

.parse(record) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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

Instance Method Details

#==(other) ⇒ Object



204
205
206
# File 'lib/ruby_gpg2/colon_record.rb', line 204

def ==(other)
  other.class == self.class && other.state == state
end

#fingerprint_record?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/ruby_gpg2/colon_record.rb', line 178

def fingerprint_record?
  type == :fingerprint
end

#user_commentObject



192
193
194
195
196
# 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_emailObject



198
199
200
201
202
# 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?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/ruby_gpg2/colon_record.rb', line 182

def user_id_record?
  type == :user_id
end

#user_nameObject



186
187
188
189
190
# File 'lib/ruby_gpg2/colon_record.rb', line 186

def user_name
  if (match = user_id&.match(USER_ID_REGEX))
    match[1]
  end
end