Module: Ronin::DB::Advisory::ID Private

Defined in:
lib/ronin/db/advisory.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Hash{Symbol => Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a security advisory ID.

Parameters:

  • string (String)

    The security advisory ID String to split.

Returns:

  • (Hash{Symbol => Object})

    The parsed security advisory ID.

Raises:

  • (ArgumentError)

    The ID does not appear to be a valid security ID.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ronin/db/advisory.rb', line 143

def self.parse(string)
  if    (match = string.match(/\A([A-Z]+)-(\d{4})[:-]([0-9][0-9-]+)\z/))
    {
      id:         match[0],
      prefix:     match[1],
      year:       match[2].to_i,
      identifier: match[3]
    }
  elsif (match = string.match(/\AMS(\d{2})-(\d{3,})\z/))
    {
      id:         match[0],
      prefix:     'MS',
      year:       2000 + match[1].to_i,
      identifier: match[2]
    }
  elsif (match = string.match(/\A([A-Z]+)-(.+)\z/))
    {
      id:         match[0],
      prefix:     match[1],
      identifier: match[2]
    }
  else
    raise(ArgumentError,"id does not appear to be a valid security advisory ID: #{string.inspect}")
  end
end