Class: Sbom::Data::SbomFile

Inherits:
Object
  • Object
show all
Defined in:
lib/sbom/data/file.rb

Constant Summary collapse

VALID_FILE_TYPES =
%w[
  SOURCE BINARY ARCHIVE APPLICATION AUDIO IMAGE
  TEXT VIDEO DOCUMENTATION SPDX OTHER
].freeze
VALID_ALGORITHMS =
%w[
  MD5 SHA1 SHA256 SHA384 SHA512
  SHA3-256 SHA3-384 SHA3-512
  BLAKE2b-256 BLAKE2b-384 BLAKE2b-512 BLAKE3
].freeze
DEFAULTS =
{
  name: "TBD",
  id: "NOT_DEFINED"
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeSbomFile

Returns a new instance of SbomFile.



22
23
24
# File 'lib/sbom/data/file.rb', line 22

def initialize
  @data = {}
end

Instance Method Details

#[](key) ⇒ Object



135
136
137
# File 'lib/sbom/data/file.rb', line 135

def [](key)
  @data[key.to_sym]
end

#[]=(key, value) ⇒ Object



139
140
141
# File 'lib/sbom/data/file.rb', line 139

def []=(key, value)
  @data[key.to_sym] = value
end

#add_checksum(algorithm, value) ⇒ Object



58
59
60
61
62
63
# File 'lib/sbom/data/file.rb', line 58

def add_checksum(algorithm, value)
  return unless valid_checksum?(value) && valid_algorithm?(algorithm)

  @data[:checksums] ||= []
  @data[:checksums] << [algorithm.strip, value.downcase]
end

#add_contributor(contributor) ⇒ Object



118
119
120
121
# File 'lib/sbom/data/file.rb', line 118

def add_contributor(contributor)
  @data[:contributors] ||= []
  @data[:contributors] << contributor
end

#add_file_type(file_type) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/sbom/data/file.rb', line 46

def add_file_type(file_type)
  type = file_type.to_s.upcase.strip
  return unless VALID_FILE_TYPES.include?(type)

  @data[:file_types] ||= []
  @data[:file_types] << type unless @data[:file_types].include?(type)
end

#add_license_info_in_file(license) ⇒ Object



77
78
79
80
# File 'lib/sbom/data/file.rb', line 77

def add_license_info_in_file(license)
  @data[:license_info_in_file] ||= []
  @data[:license_info_in_file] << license
end

#attributionObject



127
128
129
# File 'lib/sbom/data/file.rb', line 127

def attribution
  @data[:attribution]
end

#attribution=(value) ⇒ Object



131
132
133
# File 'lib/sbom/data/file.rb', line 131

def attribution=(value)
  @data[:attribution] = value
end

#checksumsObject



65
66
67
# File 'lib/sbom/data/file.rb', line 65

def checksums
  @data[:checksums] || []
end

#commentObject



102
103
104
# File 'lib/sbom/data/file.rb', line 102

def comment
  @data[:comment]
end

#comment=(value) ⇒ Object



106
107
108
# File 'lib/sbom/data/file.rb', line 106

def comment=(value)
  @data[:comment] = clean_text(value)
end

#contributorsObject



123
124
125
# File 'lib/sbom/data/file.rb', line 123

def contributors
  @data[:contributors] || []
end


94
95
96
# File 'lib/sbom/data/file.rb', line 94

def copyright_text
  @data[:copyright_text]
end


98
99
100
# File 'lib/sbom/data/file.rb', line 98

def copyright_text=(value)
  @data[:copyright_text] = clean_text(value)
end

#file_typesObject



54
55
56
# File 'lib/sbom/data/file.rb', line 54

def file_types
  @data[:file_types] || []
end

#idObject



38
39
40
# File 'lib/sbom/data/file.rb', line 38

def id
  @data[:id] || DEFAULTS[:id]
end

#id=(value) ⇒ Object



42
43
44
# File 'lib/sbom/data/file.rb', line 42

def id=(value)
  @data[:id] = value
end

#license_commentObject



86
87
88
# File 'lib/sbom/data/file.rb', line 86

def license_comment
  @data[:license_comment]
end

#license_comment=(value) ⇒ Object



90
91
92
# File 'lib/sbom/data/file.rb', line 90

def license_comment=(value)
  @data[:license_comment] = clean_text(value)
end

#license_concludedObject



69
70
71
# File 'lib/sbom/data/file.rb', line 69

def license_concluded
  @data[:license_concluded]
end

#license_concluded=(value) ⇒ Object



73
74
75
# File 'lib/sbom/data/file.rb', line 73

def license_concluded=(value)
  @data[:license_concluded] = value
end

#license_info_in_fileObject



82
83
84
# File 'lib/sbom/data/file.rb', line 82

def license_info_in_file
  @data[:license_info_in_file] || []
end

#nameObject



30
31
32
# File 'lib/sbom/data/file.rb', line 30

def name
  @data[:name] || DEFAULTS[:name]
end

#name=(value) ⇒ Object



34
35
36
# File 'lib/sbom/data/file.rb', line 34

def name=(value)
  @data[:name] = value
end

#noticeObject



110
111
112
# File 'lib/sbom/data/file.rb', line 110

def notice
  @data[:notice]
end

#notice=(value) ⇒ Object



114
115
116
# File 'lib/sbom/data/file.rb', line 114

def notice=(value)
  @data[:notice] = clean_text(value)
end

#reset!Object



26
27
28
# File 'lib/sbom/data/file.rb', line 26

def reset!
  @data = {}
end

#to_hObject



143
144
145
# File 'lib/sbom/data/file.rb', line 143

def to_h
  @data.dup
end