Skip to content

Commit 177301c

Browse files
committed
basic implementation of OoxmlCryptNative
1 parent ebd53cf commit 177301c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

ext/ooxml_crypt/extconf.rb

+13
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,17 @@
22

33
require "mkmf"
44

5+
# force usage of the C++ compiler
6+
have_library("stdc++")
7+
8+
# check for OpenSSL
9+
abort("Please install OpenSSL development libraries!") unless have_header("openssl/hmac.h") && have_library("crypto")
10+
11+
# setup build configuration
12+
vendor = File.realpath(File.join(__dir__, "..", "..", "vendor"))
13+
$INCFLAGS << " -I#{vendor}/cybozulib/include -I#{vendor}/msoffice/include"
14+
$VPATH << "#{vendor}/msoffice/src"
15+
$srcs = ["ooxml_crypt.c", "msocdll.cpp"]
16+
17+
# create makefile
518
create_makefile("ooxml_crypt/ooxml_crypt")

ext/ooxml_crypt/ooxml_crypt.c

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
#include "ooxml_crypt.h"
22

3+
VALUE rb_encrypt_file(VALUE self, VALUE inFile, VALUE password, VALUE outFile)
4+
{
5+
char *out = StringValueCStr(outFile);
6+
char *in = StringValueCStr(inFile);
7+
char *pass = StringValueCStr(password);
8+
9+
return INT2FIX(MSOC_encryptA(out, in, pass, NULL));
10+
}
11+
12+
VALUE rb_decrypt_file(VALUE self, VALUE inFile, VALUE password, VALUE outFile)
13+
{
14+
char *out = StringValueCStr(outFile);
15+
char *in = StringValueCStr(inFile);
16+
char *pass = StringValueCStr(password);
17+
18+
return INT2FIX(MSOC_decryptA(out, in, pass, NULL));
19+
}
20+
321
void Init_ooxml_crypt(void)
422
{
523
VALUE mod = rb_define_module("OoxmlCryptNative");
24+
25+
rb_define_module_function(mod, "encrypt_file", rb_encrypt_file, 3);
26+
rb_define_module_function(mod, "decrypt_file", rb_decrypt_file, 3);
627
}

ext/ooxml_crypt/ooxml_crypt.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
#define OOXML_CRYPT_H 1
33

44
#include "ruby.h"
5+
#include "msoc.h"
56

67
#endif /* OOXML_CRYPT_H */

0 commit comments

Comments
 (0)