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.



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
# File 'lib/ronin/db/advisory.rb', line 86

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