Class: Omnizip::Formats::Rpm::Tag

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/omnizip/formats/rpm/tag.rb

Overview

RPM tag definitions and value extraction

Maps tag IDs to symbolic names and handles typed value extraction from the header data blob.

Constant Summary collapse

TAG_IDS =

Tag ID to name mapping (from rpm/rpmtag.h)

{
  # Signature tags
  257 => :sigsize,
  261 => :sigmd5,
  262 => :siggpg,
  263 => :sigpgp5,
  267 => :dsaheader,
  268 => :rsaheader,
  269 => :sha1header,
  270 => :longsigsize,
  271 => :longarchivesize,

  # Header tags
  1000 => :name,
  1001 => :version,
  1002 => :release,
  1003 => :epoch,
  1004 => :summary,
  1005 => :description,
  1006 => :buildtime,
  1007 => :buildhost,
  1009 => :size,
  1010 => :distribution,
  1011 => :vendor,
  1014 => :license,
  1015 => :packager,
  1016 => :group,
  1020 => :url,
  1021 => :os,
  1022 => :arch,
  1023 => :prein,
  1024 => :postin,
  1025 => :preun,
  1026 => :postun,
  1027 => :oldfilenames,
  1028 => :filesizes,
  1029 => :filestates,
  1030 => :filemodes,
  1031 => :fileuids,
  1032 => :filegids,
  1033 => :filerdevs,
  1034 => :filemtimes,
  1035 => :filedigests,
  1036 => :filelinktos,
  1037 => :fileflags,
  1039 => :fileusername,
  1040 => :filegroupname,
  1044 => :sourcerpm,
  1046 => :archivesize,
  1047 => :providename,
  1048 => :requireflags,
  1049 => :requirename,
  1050 => :requireversion,
  1053 => :conflictflags,
  1054 => :conflictname,
  1055 => :conflictversion,
  1064 => :rpmversion,
  1090 => :obsoletename,
  1112 => :provideflags,
  1113 => :provideversion,
  1114 => :obsoleteflags,
  1115 => :obsoleteversion,
  1116 => :dirindexes,
  1117 => :basenames,
  1118 => :dirnames,
  1124 => :payloadformat,
  1125 => :payloadcompressor,
  1126 => :payloadflags,

  # Extended tags
  5000 => :filenames,
  5008 => :longfilesizes,
  5009 => :longsize,
  5013 => :evr,
  5014 => :nvr,
  5016 => :nevra,
  5019 => :epochnum,
}.freeze
TYPE_NAMES =

Type ID to name mapping

{
  TYPE_NULL => :null,
  TYPE_CHAR => :char,
  TYPE_INT8 => :int8,
  TYPE_INT16 => :int16,
  TYPE_INT32 => :int32,
  TYPE_INT64 => :int64,
  TYPE_STRING => :string,
  TYPE_BINARY => :binary,
  TYPE_STRING_ARRAY => :string_array,
  TYPE_I18NSTRING => :i18nstring,
}.freeze

Constants included from Constants

Constants::FILE_CONFIG, Constants::FILE_DOC, Constants::FILE_LICENSE, Constants::FILE_README, Constants::FLAG_EQUAL, Constants::FLAG_GREATER, Constants::FLAG_LESS, Constants::HEADER_HEADER_SIZE, Constants::HEADER_MAGIC, Constants::HEADER_SIGNED_TYPE, Constants::LEAD_MAGIC, Constants::LEAD_SIZE, Constants::PACKAGE_BINARY, Constants::PACKAGE_SOURCE, Constants::TAG_ENTRY_SIZE, Constants::TYPE_BINARY, Constants::TYPE_CHAR, Constants::TYPE_I18NSTRING, Constants::TYPE_INT16, Constants::TYPE_INT32, Constants::TYPE_INT64, Constants::TYPE_INT8, Constants::TYPE_NULL, Constants::TYPE_STRING, Constants::TYPE_STRING_ARRAY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_id, type_id, offset, count, data) ⇒ Tag

Initialize tag

Parameters:

  • tag_id (Integer)

    Tag identifier

  • type_id (Integer)

    Type identifier

  • offset (Integer)

    Offset into data blob

  • count (Integer)

    Item count

  • data (String)

    Reference to data blob



129
130
131
132
133
134
135
136
# File 'lib/omnizip/formats/rpm/tag.rb', line 129

def initialize(tag_id, type_id, offset, count, data)
  @tag_id = tag_id
  @type_id = type_id
  @offset = offset
  @count = count
  @data = data
  @value = nil
end

Instance Attribute Details

#countInteger (readonly)

Returns Count of items.

Returns:

  • (Integer)

    Count of items



117
118
119
# File 'lib/omnizip/formats/rpm/tag.rb', line 117

def count
  @count
end

#dataString (readonly)

Returns Data blob reference.

Returns:

  • (String)

    Data blob reference



120
121
122
# File 'lib/omnizip/formats/rpm/tag.rb', line 120

def data
  @data
end

#offsetInteger (readonly)

Returns Offset into data blob.

Returns:

  • (Integer)

    Offset into data blob



114
115
116
# File 'lib/omnizip/formats/rpm/tag.rb', line 114

def offset
  @offset
end

#tag_idInteger (readonly)

Returns Tag ID.

Returns:

  • (Integer)

    Tag ID



108
109
110
# File 'lib/omnizip/formats/rpm/tag.rb', line 108

def tag_id
  @tag_id
end

#type_idInteger (readonly)

Returns Tag type.

Returns:

  • (Integer)

    Tag type



111
112
113
# File 'lib/omnizip/formats/rpm/tag.rb', line 111

def type_id
  @type_id
end

Instance Method Details

#nameSymbol, Integer

Get tag name

Returns:

  • (Symbol, Integer)

    Tag name or ID if unknown



141
142
143
# File 'lib/omnizip/formats/rpm/tag.rb', line 141

def name
  TAG_IDS.fetch(@tag_id, @tag_id)
end

#typeSymbol, Integer

Get type name

Returns:

  • (Symbol, Integer)

    Type name or ID if unknown



148
149
150
# File 'lib/omnizip/formats/rpm/tag.rb', line 148

def type
  TYPE_NAMES.fetch(@type_id, @type_id)
end

#valueObject

Get tag value (lazy extraction)

Returns:

  • (Object)

    Extracted value based on type



155
156
157
158
159
# File 'lib/omnizip/formats/rpm/tag.rb', line 155

def value
  return @value if @value

  @value = extract_value
end