module Capsium::Package::Preparation
Package-source preparation (ARCHITECTURE.md section 1), mixed into Package: directory/.cap/encrypted-cap detection, extraction and decryption into a readable package directory.
Public Instance Methods
(String | Pathname file_path) → String
Source
# File lib/capsium/package/preparation.rb, line 21 def decompress_cap_file(file_path) package_path = File.join(Dir.mktmpdir, package_stem(file_path)) FileUtils.mkdir_p(package_path) Packager.new.unpack(file_path, package_path) package_path end
(String | Pathname source_path) → String
Source
# File lib/capsium/package/preparation.rb, line 32 def decrypt_cap_file(source_path) unless @decryption_key raise Cipher::KeyRequiredError, "Package is encrypted; provide the private key via decryption_key:" end Cipher.decrypt_to_directory(source_path, @decryption_key) end
Decrypts an encrypted package (.cap file or uncompressed directory) into a temporary directory and returns its path. The metadata.json of an encrypted package stays cleartext, but everything else is only readable with the recipient’s private key.
(String | Pathname path) → Symbol
Source
# File lib/capsium/package/preparation.rb, line 41 def determine_load_type(path) return :directory if File.directory?(path) File.extname(path) == ".cap" ? :cap_file : :unsaved end
() → bool
Source
# File lib/capsium/package/preparation.rb, line 49 def encrypted? Cipher.encrypted?(@original_path) end
Whether the package was loaded from an encrypted source (ARCHITECTURE.md section 6b layout).
(Pathname path) → (String | Pathname)
Source
# File lib/capsium/package/preparation.rb, line 12 def prepare_package(path) return decrypt_cap_file(path) if Cipher.encrypted?(path) return path if File.directory?(path) raise Error, "Invalid package path: #{path}" unless File.file?(path) raise Error, "The package must have a .cap extension" unless File.extname(path) == ".cap" decompress_cap_file(path) end