Class: Axlsx::Cbf

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/util/cbf.rb

Overview

The Cfb class is a MS-OFF-CRYPTOGRAPHY specific OLE (MS-CBF) writer implementation. No attempt is made to re-invent the wheel for read/write of compound binary files.

Constant Summary collapse

FAT_PACKING =

the serialization for the CBF FAT

"s128"
VERSION_PACKING =

the serialization for the MS-OFF-CRYPTO version stream

'l s30 l3'
DATA_SPACE_MAP_PACKING =

The serialization for the MS-OFF-CRYPTO dataspace map stream

'l6 s16 l s25 x2'
STRONG_ENCRYPTION_DATA_SPACE_PACKING =

The serialization for the MS-OFF-CRYPTO strong encrytion data space stream

'l3 s26'
PRIMARY_PACKING =

The serialization for the MS-OFF-CRYPTO primary stream

'l3 s38 l s40 l3 x12 l'
MINI_CUTOFF =

The cutoff size that determines if a stream should be in the mini-fat or the fat

4096
HEADER_PACKING =

The serialization for CBF header

"q x16 l s3 x10 l l x4 l*"

Instance Method Summary collapse

Constructor Details

#initialize(ms_off_crypto) ⇒ Cbf

Creates a new Cbf object based on the ms_off_crypto object provided.

Parameters:



30
31
32
33
34
35
36
37
38
# File 'lib/axlsx/util/cbf.rb', line 30

def initialize(ms_off_crypto)
  @file_name = ms_off_crypto.file_name  
  @ms_off_crypto = ms_off_crypto
  create_storages
  mini_fat_stream
  mini_fat
  fat
  header
end

Instance Method Details

#data_space_mapStorage

returns the data space map storage

Returns:



48
49
50
# File 'lib/axlsx/util/cbf.rb', line 48

def data_space_map
  @data_space_map ||= create_data_space_map
end

#document_summary_informationStorage

returns the document summary information

Returns:



66
67
68
# File 'lib/axlsx/util/cbf.rb', line 66

def document_summary_information
  @document_summary_information ||= create_document_summary_information
end

#encrypted_packageString

returns the encrypted package from the ms_off_crypt object provided during initalization

Returns:

  • (String)

    encrypted package



108
109
110
# File 'lib/axlsx/util/cbf.rb', line 108

def encrypted_package
  @ms_off_crypto.encrypted_package
end

#encryption_infoString

returns the encryption info from the ms_off_crypt object provided during intialization

Returns:

  • (String)

    encryption info



102
103
104
# File 'lib/axlsx/util/cbf.rb', line 102

def encryption_info
  @ms_off_crypto.encryption_info
end

#fatString

returns the fat

Returns:

  • (String)


90
91
92
# File 'lib/axlsx/util/cbf.rb', line 90

def fat
  @fat ||= create_fat
end

#fat_streamString

returns the stream of data allocated in the fat

Returns:

  • (String)


72
73
74
# File 'lib/axlsx/util/cbf.rb', line 72

def fat_stream 
  @fat_stream ||= create_fat_stream
end

#headerString

returns the CFB header

Returns:

  • (String)


96
97
98
# File 'lib/axlsx/util/cbf.rb', line 96

def header
  @header ||= create_header
end

#mini_fatObject

returns the mini fat return [String]



84
85
86
# File 'lib/axlsx/util/cbf.rb', line 84

def mini_fat
  @mini_fat ||= create_mini_fat
end

#mini_fat_streamObject

returns the stream allocated in the mini fat. return [String]



78
79
80
# File 'lib/axlsx/util/cbf.rb', line 78

def mini_fat_stream
  @mini_fat_stream ||= create_mini_fat_stream
end

#primaryStorgae

returns the primary storage

Returns:

  • (Storgae)


54
55
56
# File 'lib/axlsx/util/cbf.rb', line 54

def primary
  @primary ||= create_primary
end

#saveObject

writes the compound binary file to disk



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/axlsx/util/cbf.rb', line 113

def save
  ole = File.open(@file_name, 'w')
  ole << header
  ole << fat
  @storages.each { |s| ole << s.to_s }
  ole << Array.new((512-(ole.pos % 512)), 0).pack('c*')
  ole << mini_fat
  ole << mini_fat_stream
  ole << fat_stream
  ole.close
end

#summary_informationStorage

returns the summary information storage

Returns:



60
61
62
# File 'lib/axlsx/util/cbf.rb', line 60

def summary_information
  @summary_information ||= create_summary_information
end

#versionStorage

creates or returns the version storage

Returns:



42
43
44
# File 'lib/axlsx/util/cbf.rb', line 42

def version
  @version ||= create_version
end