Class: OoxmlParser::EncryptionChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/common_parser/parser/encryption_checker.rb

Overview

Check if file is encrypted

Instance Method Summary collapse

Constructor Details

#initialize(file_path, ignore_system: false) ⇒ EncryptionChecker

Returns a new instance of EncryptionChecker.



6
7
8
9
# File 'lib/ooxml_parser/common_parser/parser/encryption_checker.rb', line 6

def initialize(file_path, ignore_system: false)
  @file_path = file_path
  @ignore_system = ignore_system
end

Instance Method Details

#encrypted?Boolean

Returns is file encrypted.

Returns:

  • (Boolean)

    is file encrypted



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ooxml_parser/common_parser/parser/encryption_checker.rb', line 12

def encrypted?
  return false unless compatible_system?

  # Support of Encrypted status in `file` util was introduced in file v5.20
  # but LTS version of ubuntu before 16.04 uses older `file` and it return `Composite Document`
  # https://github.com/file/file/blob/0eb7c1b83341cc954620b45d2e2d65ee7df1a4e7/ChangeLog#L623
  if mime_type.include?('encrypted') ||
     mime_type.include?('Composite Document File V2 Document, No summary info') ||
     mime_type.include?('application/CDFV2-corrupt')
    warn("File #{@file_path} is encrypted. Can't parse it")
    return true
  end
  false
end