Module: OoxmlCrypt
- Defined in:
- lib/ooxml_crypt.rb,
lib/ooxml_crypt/version.rb,
ext/ooxml_crypt/ooxml_crypt.c
Defined Under Namespace
Modules: Native
Classes: EmptyPassword, Error, FileNotFound
Constant Summary
collapse
- ERRORS =
should be kept in sync with msoc.h
{
1 => "not supported format",
2 => "already encrypted",
3 => "already decrypted",
4 => "bad password",
5 => "bad parameter",
6 => "small max size",
7 => "no memory",
8 => "internal exception",
9 => "too large file",
10 => "inFile is empty",
11 => "outFile is empty",
12 => "password is empty",
}
- VERSION =
"0.1.4"
Class Method Summary
collapse
Class Method Details
.decrypt(data, password) ⇒ Object
50
51
52
53
54
|
# File 'lib/ooxml_crypt.rb', line 50
def self.decrypt(data, password)
with_temp_files(data) do |input, output|
decrypt_file(input, password, output)
end
end
|
.decrypt_file(input, password, output) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/ooxml_crypt.rb', line 36
def self.decrypt_file(input, password, output)
raise EmptyPassword if password.nil? || password.empty?
raise FileNotFound, input unless File.exist?(input)
result = Native.decrypt_file(input, password, output)
raise Error, ERRORS[-result] if result != 0
end
|
.encrypt(data, password) ⇒ Object
44
45
46
47
48
|
# File 'lib/ooxml_crypt.rb', line 44
def self.encrypt(data, password)
with_temp_files(data) do |input, output|
encrypt_file(input, password, output)
end
end
|
.encrypt_file(input, password, output) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/ooxml_crypt.rb', line 28
def self.encrypt_file(input, password, output)
raise EmptyPassword if password.nil? || password.empty?
raise FileNotFound, input unless File.exist?(input)
result = Native.encrypt_file(input, password, output)
raise Error, ERRORS[-result] if result != 0
end
|