krypt-core 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/ext/krypt/core/Makefile +221 -0
- data/ext/krypt/core/binyo-error.h +40 -0
- data/ext/krypt/core/binyo-io-buffer.h +54 -0
- data/ext/krypt/core/binyo-io.h +131 -0
- data/ext/krypt/core/extconf.h +8 -0
- data/ext/krypt/core/extconf.rb +80 -0
- data/ext/krypt/core/krypt-core.c +110 -0
- data/ext/krypt/core/krypt-core.h +97 -0
- data/ext/krypt/core/krypt-core.o +0 -0
- data/ext/krypt/core/krypt-provider.h +86 -0
- data/ext/krypt/core/krypt_asn1-internal.c +681 -0
- data/ext/krypt/core/krypt_asn1-internal.h +117 -0
- data/ext/krypt/core/krypt_asn1-internal.o +0 -0
- data/ext/krypt/core/krypt_asn1.c +2109 -0
- data/ext/krypt/core/krypt_asn1.h +88 -0
- data/ext/krypt/core/krypt_asn1.o +0 -0
- data/ext/krypt/core/krypt_asn1_codec.c +973 -0
- data/ext/krypt/core/krypt_asn1_codec.o +0 -0
- data/ext/krypt/core/krypt_asn1_in_adapter.c +178 -0
- data/ext/krypt/core/krypt_asn1_in_adapter.o +0 -0
- data/ext/krypt/core/krypt_asn1_in_chunked.c +292 -0
- data/ext/krypt/core/krypt_asn1_in_chunked.o +0 -0
- data/ext/krypt/core/krypt_asn1_in_definite.c +156 -0
- data/ext/krypt/core/krypt_asn1_in_definite.o +0 -0
- data/ext/krypt/core/krypt_asn1_parser.c +592 -0
- data/ext/krypt/core/krypt_asn1_parser.o +0 -0
- data/ext/krypt/core/krypt_asn1_template-internal.h +185 -0
- data/ext/krypt/core/krypt_asn1_template.c +459 -0
- data/ext/krypt/core/krypt_asn1_template.h +56 -0
- data/ext/krypt/core/krypt_asn1_template.o +0 -0
- data/ext/krypt/core/krypt_asn1_template_encoder.c +76 -0
- data/ext/krypt/core/krypt_asn1_template_encoder.o +0 -0
- data/ext/krypt/core/krypt_asn1_template_parser.c +1176 -0
- data/ext/krypt/core/krypt_asn1_template_parser.o +0 -0
- data/ext/krypt/core/krypt_b64-internal.h +38 -0
- data/ext/krypt/core/krypt_b64.c +391 -0
- data/ext/krypt/core/krypt_b64.h +41 -0
- data/ext/krypt/core/krypt_b64.o +0 -0
- data/ext/krypt/core/krypt_digest.c +391 -0
- data/ext/krypt/core/krypt_digest.h +51 -0
- data/ext/krypt/core/krypt_digest.o +0 -0
- data/ext/krypt/core/krypt_error.c +221 -0
- data/ext/krypt/core/krypt_error.h +46 -0
- data/ext/krypt/core/krypt_error.o +0 -0
- data/ext/krypt/core/krypt_hex-internal.h +36 -0
- data/ext/krypt/core/krypt_hex.c +255 -0
- data/ext/krypt/core/krypt_hex.h +41 -0
- data/ext/krypt/core/krypt_hex.o +0 -0
- data/ext/krypt/core/krypt_io.c +65 -0
- data/ext/krypt/core/krypt_io.h +56 -0
- data/ext/krypt/core/krypt_io.o +0 -0
- data/ext/krypt/core/krypt_io_in_pem.c +397 -0
- data/ext/krypt/core/krypt_io_in_pem.o +0 -0
- data/ext/krypt/core/krypt_missing.c +238 -0
- data/ext/krypt/core/krypt_missing.h +62 -0
- data/ext/krypt/core/krypt_missing.o +0 -0
- data/ext/krypt/core/krypt_pem.c +171 -0
- data/ext/krypt/core/krypt_pem.o +0 -0
- data/ext/krypt/core/krypt_provider-internal.h +40 -0
- data/ext/krypt/core/krypt_provider.c +136 -0
- data/ext/krypt/core/krypt_provider.o +0 -0
- data/ext/krypt/core/kryptcore.so +0 -0
- data/ext/krypt/core/mkmf.log +130 -0
- data/lib/krypt-core/version.rb +3 -0
- data/lib/krypt-core.rb +35 -0
- data/lib/kryptcore.so +0 -0
- data/spec/README +2 -0
- data/test/README +2 -0
- data/test/res/certificate.cer +0 -0
- data/test/resources.rb +48 -0
- data/test/scratch.rb +17 -0
- metadata +150 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011-2013 Hiroshi Nakamura, Martin Boßlet
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,221 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
# V=0 quiet, V=1 verbose. other values don't work.
|
5
|
+
V = 0
|
6
|
+
Q1 = $(V:1=)
|
7
|
+
Q = $(Q1:0=@)
|
8
|
+
ECHO1 = $(V:1=@:)
|
9
|
+
ECHO = $(ECHO1:0=@echo)
|
10
|
+
|
11
|
+
#### Start of system configuration section. ####
|
12
|
+
|
13
|
+
srcdir = .
|
14
|
+
topdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
15
|
+
hdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
16
|
+
arch_hdrdir = $(hdrdir)/$(arch)
|
17
|
+
VPATH = $(srcdir):$(topdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
18
|
+
prefix = $(DESTDIR)/home/martin/ruby
|
19
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
20
|
+
exec_prefix = $(prefix)
|
21
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
22
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
23
|
+
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
24
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
25
|
+
sitedir = $(rubylibprefix)/site_ruby
|
26
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
27
|
+
mandir = $(datarootdir)/man
|
28
|
+
localedir = $(datarootdir)/locale
|
29
|
+
libdir = $(exec_prefix)/lib
|
30
|
+
psdir = $(docdir)
|
31
|
+
pdfdir = $(docdir)
|
32
|
+
dvidir = $(docdir)
|
33
|
+
htmldir = $(docdir)
|
34
|
+
infodir = $(datarootdir)/info
|
35
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
36
|
+
oldincludedir = $(DESTDIR)/usr/include
|
37
|
+
includedir = $(prefix)/include
|
38
|
+
localstatedir = $(prefix)/var
|
39
|
+
sharedstatedir = $(prefix)/com
|
40
|
+
sysconfdir = $(prefix)/etc
|
41
|
+
datadir = $(datarootdir)
|
42
|
+
datarootdir = $(prefix)/share
|
43
|
+
libexecdir = $(exec_prefix)/libexec
|
44
|
+
sbindir = $(exec_prefix)/sbin
|
45
|
+
bindir = $(exec_prefix)/bin
|
46
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
47
|
+
archdir = $(rubylibdir)/$(arch)
|
48
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
49
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
50
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
51
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
52
|
+
|
53
|
+
|
54
|
+
CC = gcc
|
55
|
+
CXX = g++
|
56
|
+
LIBRUBY = $(LIBRUBY_A)
|
57
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
58
|
+
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir)
|
59
|
+
LIBRUBYARG_STATIC = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static
|
60
|
+
empty =
|
61
|
+
OUTFLAG = -o $(empty)
|
62
|
+
COUTFLAG = -o $(empty)
|
63
|
+
|
64
|
+
RUBY_EXTCONF_H = extconf.h
|
65
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
66
|
+
optflags = -O3 -fno-fast-math
|
67
|
+
debugflags = -ggdb3
|
68
|
+
warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
|
69
|
+
CFLAGS = -fPIC $(cflags) $(ARCH_FLAG)
|
70
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
71
|
+
DEFS =
|
72
|
+
CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" $(DEFS) $(cppflags)
|
73
|
+
CXXFLAGS = $(CFLAGS) $(cxxflags)
|
74
|
+
ldflags = -L. -fstack-protector -rdynamic -Wl,-export-dynamic
|
75
|
+
dldflags =
|
76
|
+
ARCH_FLAG =
|
77
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
78
|
+
LDSHARED = $(CC) -shared
|
79
|
+
LDSHAREDXX = $(CXX) -shared
|
80
|
+
AR = ar
|
81
|
+
EXEEXT =
|
82
|
+
|
83
|
+
RUBY_BASE_NAME = ruby
|
84
|
+
RUBY_INSTALL_NAME = ruby
|
85
|
+
RUBY_SO_NAME = ruby
|
86
|
+
arch = x86_64-linux
|
87
|
+
sitearch = $(arch)
|
88
|
+
ruby_version = 2.0.0
|
89
|
+
ruby = $(bindir)/ruby
|
90
|
+
RUBY = $(ruby)
|
91
|
+
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h $(RUBY_EXTCONF_H)
|
92
|
+
|
93
|
+
RM = rm -f
|
94
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
95
|
+
RMDIRS = rmdir --ignore-fail-on-non-empty -p
|
96
|
+
MAKEDIRS = /bin/mkdir -p
|
97
|
+
INSTALL = /usr/bin/install -c
|
98
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
99
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
100
|
+
COPY = cp
|
101
|
+
TOUCH = exit >
|
102
|
+
|
103
|
+
#### End of system configuration section. ####
|
104
|
+
|
105
|
+
preload =
|
106
|
+
|
107
|
+
libpath = . $(libdir)
|
108
|
+
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir)
|
109
|
+
DEFFILE =
|
110
|
+
|
111
|
+
CLEANFILES = mkmf.log
|
112
|
+
DISTCLEANFILES =
|
113
|
+
DISTCLEANDIRS =
|
114
|
+
|
115
|
+
extout =
|
116
|
+
extout_prefix =
|
117
|
+
target_prefix =
|
118
|
+
LOCAL_LIBS =
|
119
|
+
LIBS = -lpthread -lrt -ldl -lcrypt -lm -lc
|
120
|
+
ORIG_SRCS = krypt_asn1_in_adapter.c krypt_asn1_in_definite.c krypt_io_in_pem.c krypt_hex.c krypt_provider.c krypt_asn1-internal.c krypt_error.c krypt_asn1_template_encoder.c krypt_asn1_parser.c krypt-core.c krypt_io.c krypt_digest.c krypt_missing.c krypt_asn1_template_parser.c krypt_asn1_template.c krypt_pem.c krypt_asn1_codec.c krypt_b64.c krypt_asn1_in_chunked.c krypt_asn1.c
|
121
|
+
SRCS = $(ORIG_SRCS)
|
122
|
+
OBJS = krypt_asn1_in_adapter.o krypt_asn1_in_definite.o krypt_io_in_pem.o krypt_hex.o krypt_provider.o krypt_asn1-internal.o krypt_error.o krypt_asn1_template_encoder.o krypt_asn1_parser.o krypt-core.o krypt_io.o krypt_digest.o krypt_missing.o krypt_asn1_template_parser.o krypt_asn1_template.o krypt_pem.o krypt_asn1_codec.o krypt_b64.o krypt_asn1_in_chunked.o krypt_asn1.o
|
123
|
+
HDRS = $(srcdir)/krypt_io.h $(srcdir)/krypt_missing.h $(srcdir)/krypt-core.h $(srcdir)/binyo-io-buffer.h $(srcdir)/krypt_asn1.h $(srcdir)/krypt_asn1_template-internal.h $(srcdir)/binyo-error.h $(srcdir)/krypt_hex.h $(srcdir)/krypt_digest.h $(srcdir)/binyo-io.h $(srcdir)/krypt_b64.h $(srcdir)/krypt_asn1-internal.h $(srcdir)/krypt_b64-internal.h $(srcdir)/extconf.h $(srcdir)/krypt_error.h $(srcdir)/krypt_hex-internal.h $(srcdir)/krypt-provider.h $(srcdir)/krypt_provider-internal.h $(srcdir)/krypt_asn1_template.h
|
124
|
+
TARGET = kryptcore
|
125
|
+
TARGET_NAME = kryptcore
|
126
|
+
TARGET_ENTRY = Init_$(TARGET_NAME)
|
127
|
+
DLLIB = $(TARGET).so
|
128
|
+
EXTSTATIC =
|
129
|
+
STATIC_LIB =
|
130
|
+
|
131
|
+
BINDIR = $(bindir)
|
132
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
133
|
+
RUBYLIBDIR = /home/martin/Projekte/krypt/emboss/krypt-core-c/lib$(target_prefix)
|
134
|
+
RUBYARCHDIR = /home/martin/Projekte/krypt/emboss/krypt-core-c/lib$(target_prefix)
|
135
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
136
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
137
|
+
|
138
|
+
TARGET_SO = $(DLLIB)
|
139
|
+
CLEANLIBS = $(TARGET).so
|
140
|
+
CLEANOBJS = *.o *.bak
|
141
|
+
|
142
|
+
all: $(DLLIB)
|
143
|
+
static: $(STATIC_LIB)
|
144
|
+
.PHONY: all install static install-so install-rb
|
145
|
+
.PHONY: clean clean-so clean-static clean-rb
|
146
|
+
|
147
|
+
clean-static::
|
148
|
+
clean-rb-default::
|
149
|
+
clean-rb::
|
150
|
+
clean-so::
|
151
|
+
clean: clean-so clean-static clean-rb-default clean-rb
|
152
|
+
-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
153
|
+
|
154
|
+
distclean-rb-default::
|
155
|
+
distclean-rb::
|
156
|
+
distclean-so::
|
157
|
+
distclean-static::
|
158
|
+
distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
|
159
|
+
-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
160
|
+
-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
161
|
+
-$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
162
|
+
|
163
|
+
realclean: distclean
|
164
|
+
install: install-so install-rb
|
165
|
+
|
166
|
+
install-so: $(DLLIB)
|
167
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
168
|
+
clean-static::
|
169
|
+
-$(Q)$(RM) $(STATIC_LIB)
|
170
|
+
install-rb: pre-install-rb install-rb-default
|
171
|
+
install-rb-default: pre-install-rb-default
|
172
|
+
pre-install-rb: Makefile
|
173
|
+
pre-install-rb-default: Makefile
|
174
|
+
pre-install-rb-default:
|
175
|
+
$(ECHO) installing default kryptcore libraries
|
176
|
+
./.RUBYARCHDIR.time:
|
177
|
+
$(Q) $(MAKEDIRS) $(RUBYARCHDIR)
|
178
|
+
$(Q) $(TOUCH) $@
|
179
|
+
|
180
|
+
site-install: site-install-so site-install-rb
|
181
|
+
site-install-so: install-so
|
182
|
+
site-install-rb: install-rb
|
183
|
+
|
184
|
+
.SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
|
185
|
+
|
186
|
+
.cc.o:
|
187
|
+
$(ECHO) compiling $(<)
|
188
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
189
|
+
|
190
|
+
.mm.o:
|
191
|
+
$(ECHO) compiling $(<)
|
192
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
193
|
+
|
194
|
+
.cxx.o:
|
195
|
+
$(ECHO) compiling $(<)
|
196
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
197
|
+
|
198
|
+
.cpp.o:
|
199
|
+
$(ECHO) compiling $(<)
|
200
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
201
|
+
|
202
|
+
.C.o:
|
203
|
+
$(ECHO) compiling $(<)
|
204
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
205
|
+
|
206
|
+
.c.o:
|
207
|
+
$(ECHO) compiling $(<)
|
208
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
209
|
+
|
210
|
+
.m.o:
|
211
|
+
$(ECHO) compiling $(<)
|
212
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
213
|
+
|
214
|
+
$(DLLIB): $(OBJS) Makefile
|
215
|
+
$(ECHO) linking shared-object $(DLLIB)
|
216
|
+
-$(Q)$(RM) $(@)
|
217
|
+
$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
$(OBJS): $(HDRS) $(ruby_headers)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* binyo - Fast binary IO for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012-2013
|
5
|
+
* Martin Bosslet <martin.bosslet@gmail.com>
|
6
|
+
* All rights reserved.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
* a copy of this software and associated documentation files (the
|
10
|
+
* "Software"), to deal in the Software without restriction, including
|
11
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
* the following conditions:
|
15
|
+
*
|
16
|
+
* The above copyright notice and this permission notice shall be
|
17
|
+
* included in all copies or substantial portions of the Software.
|
18
|
+
*
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
#ifndef _BINYO_ERROR_H_
|
28
|
+
#define _BINYO_ERROR_H_
|
29
|
+
|
30
|
+
#define BINYO_OK 1
|
31
|
+
#define BINYO_ERR -1
|
32
|
+
|
33
|
+
#define BINYO_IO_EOF -2
|
34
|
+
|
35
|
+
int binyo_has_errors(void);
|
36
|
+
int binyo_error_message(char *buf, int buf_len);
|
37
|
+
void binyo_error_clear(void);
|
38
|
+
|
39
|
+
#endif /* BINYO_ERROR_H */
|
40
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* binyo - Fast binary IO for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012-2013
|
5
|
+
* Martin Bosslet <martin.bosslet@gmail.com>
|
6
|
+
* All rights reserved.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
* a copy of this software and associated documentation files (the
|
10
|
+
* "Software"), to deal in the Software without restriction, including
|
11
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
* the following conditions:
|
15
|
+
*
|
16
|
+
* The above copyright notice and this permission notice shall be
|
17
|
+
* included in all copies or substantial portions of the Software.
|
18
|
+
*
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#if !defined(_BINYO_IO_BUFFER_H_)
|
29
|
+
#define _BINYO_IO_BUFFER_H_
|
30
|
+
|
31
|
+
#include <ruby.h>
|
32
|
+
|
33
|
+
#define BINYO_BYTE_BUFFER_GROWTH_FACTOR 2
|
34
|
+
|
35
|
+
typedef struct binyo_byte_buffer_st {
|
36
|
+
size_t size;
|
37
|
+
size_t limit;
|
38
|
+
size_t init_size;
|
39
|
+
int prealloc; /* whether the buffer was already preallocated */
|
40
|
+
uint8_t *data;
|
41
|
+
} binyo_byte_buffer;
|
42
|
+
|
43
|
+
#define binyo_buffer_get_data(b) (b)->data
|
44
|
+
#define binyo_buffer_get_size(b) (b)->size
|
45
|
+
binyo_byte_buffer *binyo_buffer_new(void);
|
46
|
+
binyo_byte_buffer *binyo_buffer_new_size(size_t size);
|
47
|
+
binyo_byte_buffer *binyo_buffer_new_prealloc(uint8_t *b, size_t len);
|
48
|
+
ssize_t binyo_buffer_write(binyo_byte_buffer *buffer, uint8_t *b, size_t len);
|
49
|
+
void binyo_buffer_free_secure(binyo_byte_buffer *buffer);
|
50
|
+
void binyo_buffer_free(binyo_byte_buffer *buffer);
|
51
|
+
|
52
|
+
size_t binyo_buffer_get_bytes_free(binyo_byte_buffer *buffer, uint8_t **out);
|
53
|
+
|
54
|
+
#endif /* _BINYO_IO_BUFFER_H_ */
|
@@ -0,0 +1,131 @@
|
|
1
|
+
/*
|
2
|
+
* binyo - Fast binary IO for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012-2013
|
5
|
+
* Martin Bosslet <martin.bosslet@gmail.com>
|
6
|
+
* All rights reserved.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
* a copy of this software and associated documentation files (the
|
10
|
+
* "Software"), to deal in the Software without restriction, including
|
11
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
* the following conditions:
|
15
|
+
*
|
16
|
+
* The above copyright notice and this permission notice shall be
|
17
|
+
* included in all copies or substantial portions of the Software.
|
18
|
+
*
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#if !defined(_BINYO_IO_H_)
|
29
|
+
#define _BINYO_IO_H_
|
30
|
+
|
31
|
+
#include "binyo-io-buffer.h"
|
32
|
+
|
33
|
+
extern ID sBinyo_ID_READ, sBinyo_ID_SEEK, sBinyo_ID_WRITE, sBinyo_ID_CLOSE;
|
34
|
+
|
35
|
+
extern VALUE sBinyo_ID_SEEK_CUR, sBinyo_ID_SEEK_SET, sBinyo_ID_SEEK_END;
|
36
|
+
|
37
|
+
#define BINYO_IO_BUF_SIZE 8192
|
38
|
+
|
39
|
+
#define BINYO_INSTREAM_TYPE_FD 0
|
40
|
+
#define BINYO_INSTREAM_TYPE_BYTES 1
|
41
|
+
#define BINYO_INSTREAM_TYPE_IO_GENERIC 2
|
42
|
+
#define BINYO_INSTREAM_TYPE_SEQ 3
|
43
|
+
#define BINYO_INSTREAM_TYPE_CACHE 4
|
44
|
+
|
45
|
+
#define BINYO_OUTSTREAM_TYPE_FD 10
|
46
|
+
#define BINYO_OUTSTREAM_TYPE_BYTES 11
|
47
|
+
#define BINYO_OUTSTREAM_TYPE_IO_GENERIC 12
|
48
|
+
|
49
|
+
typedef struct binyo_instream_interface_st binyo_instream_interface;
|
50
|
+
typedef struct binyo_outstream_interface_st binyo_outstream_interface;
|
51
|
+
|
52
|
+
typedef struct binyo_instream_st {
|
53
|
+
binyo_instream_interface *methods;
|
54
|
+
} binyo_instream;
|
55
|
+
|
56
|
+
typedef struct binyo_out_stream_st {
|
57
|
+
binyo_outstream_interface *methods;
|
58
|
+
} binyo_outstream;
|
59
|
+
|
60
|
+
struct binyo_instream_interface_st {
|
61
|
+
int type;
|
62
|
+
|
63
|
+
ssize_t (*read)(binyo_instream*, uint8_t*, size_t);
|
64
|
+
int (*rb_read)(binyo_instream*, VALUE, VALUE, VALUE*);
|
65
|
+
ssize_t (*gets)(binyo_instream*, char *, size_t);
|
66
|
+
int (*seek)(binyo_instream*, off_t, int);
|
67
|
+
void (*mark)(binyo_instream*);
|
68
|
+
void (*free)(binyo_instream*);
|
69
|
+
};
|
70
|
+
|
71
|
+
struct binyo_outstream_interface_st {
|
72
|
+
int type;
|
73
|
+
|
74
|
+
ssize_t (*write)(binyo_outstream*, uint8_t *buf, size_t);
|
75
|
+
int (*rb_write)(binyo_outstream*, VALUE, VALUE*);
|
76
|
+
void (*mark)(binyo_outstream*);
|
77
|
+
void (*free)(binyo_outstream*);
|
78
|
+
};
|
79
|
+
|
80
|
+
#define binyo_safe_cast_stream(out, in, t, ptype, stype) \
|
81
|
+
do { \
|
82
|
+
if (!(in)) \
|
83
|
+
rb_raise(rb_eRuntimeError, "Uninitialized stream."); \
|
84
|
+
if (((stype *) (in))->methods->type == (t)) { \
|
85
|
+
out = (ptype *) in; \
|
86
|
+
} \
|
87
|
+
else { \
|
88
|
+
int errt = ((stype *) (in))->methods->type; \
|
89
|
+
rb_raise(rb_eArgError, "Unknown type: %d", errt); \
|
90
|
+
} \
|
91
|
+
} while (0) \
|
92
|
+
|
93
|
+
#define binyo_safe_cast_outstream(out, in, type, ptrtype) binyo_safe_cast_stream((out), (in), (type), ptrtype, binyo_outstream)
|
94
|
+
#define binyo_safe_cast_instream(out, in, type, ptrtype) binyo_safe_cast_stream((out), (in), (type), ptrtype, binyo_instream)
|
95
|
+
|
96
|
+
ssize_t binyo_instream_read(binyo_instream *in, uint8_t *buf, size_t len);
|
97
|
+
int binyo_instream_rb_read(binyo_instream *in, VALUE vlen, VALUE vbuf, VALUE *out);
|
98
|
+
ssize_t binyo_instream_gets(binyo_instream *in, char *line, size_t len);
|
99
|
+
int binyo_instream_seek(binyo_instream *in, off_t offset, int whence);
|
100
|
+
#define binyo_instream_skip(in, n) binyo_instream_seek((in), (n), SEEK_CUR)
|
101
|
+
void binyo_instream_mark(binyo_instream *in);
|
102
|
+
void binyo_instream_free(binyo_instream *in);
|
103
|
+
|
104
|
+
binyo_instream *binyo_instream_new_fd(int fd);
|
105
|
+
binyo_instream *binyo_instream_new_fd_io(VALUE io);
|
106
|
+
binyo_instream *binyo_instream_new_bytes(uint8_t *bytes, size_t len);
|
107
|
+
binyo_instream *binyo_instream_new_io_generic(VALUE io);
|
108
|
+
binyo_instream *binyo_instream_new_value(VALUE value);
|
109
|
+
binyo_instream *binyo_instream_new_seq(binyo_instream *in1, binyo_instream *in2);
|
110
|
+
binyo_instream *binyo_instream_new_seq_n(int num, binyo_instream *in1, binyo_instream *in2, ...);
|
111
|
+
binyo_instream *binyo_instream_new_cache(binyo_instream *original);
|
112
|
+
void binyo_instream_cache_free_wrapper(binyo_instream *instream);
|
113
|
+
size_t binyo_instream_cache_get_bytes(binyo_instream *in, uint8_t **out);
|
114
|
+
|
115
|
+
ssize_t binyo_outstream_write(binyo_outstream *out, uint8_t *buf, size_t len);
|
116
|
+
int binyo_outstream_rb_write(binyo_outstream *out, VALUE vbuf, VALUE *ret);
|
117
|
+
void binyo_outstream_mark(binyo_outstream *in);
|
118
|
+
void binyo_outstream_free(binyo_outstream *out);
|
119
|
+
|
120
|
+
size_t binyo_outstream_bytes_get_bytes_free(binyo_outstream *outstream, uint8_t **bytes);
|
121
|
+
|
122
|
+
binyo_outstream *binyo_outstream_new_fd(int fd);
|
123
|
+
binyo_outstream *binyo_outstream_new_fd_io(VALUE io);
|
124
|
+
binyo_outstream *binyo_outstream_new_bytes(void);
|
125
|
+
binyo_outstream *binyo_outstream_new_bytes_size(size_t size);
|
126
|
+
binyo_outstream *binyo_outstream_new_bytes_prealloc(uint8_t *b, size_t len);
|
127
|
+
binyo_outstream *binyo_outstream_new_io_generic(VALUE io);
|
128
|
+
binyo_outstream *binyo_outstream_new_value(VALUE value);
|
129
|
+
|
130
|
+
#endif /* _BINYO_IO_H_ */
|
131
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
= Info
|
4
|
+
|
5
|
+
krypt-core API - C implementation
|
6
|
+
|
7
|
+
Copyright (C) 2011-2013
|
8
|
+
Hiroshi Nakamura <nahi@ruby-lang.org>
|
9
|
+
Martin Bosslet <martin.bosslet@gmail.com>
|
10
|
+
All rights reserved.
|
11
|
+
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
a copy of this software and associated documentation files (the
|
14
|
+
"Software"), to deal in the Software without restriction, including
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be
|
21
|
+
included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
|
31
|
+
=end
|
32
|
+
|
33
|
+
require 'mkmf'
|
34
|
+
|
35
|
+
dir_config('profiler')
|
36
|
+
|
37
|
+
message "=== krypt-core API - C version ===\n"
|
38
|
+
|
39
|
+
arg = ARGV.shift
|
40
|
+
if arg
|
41
|
+
if arg.include? "-g"
|
42
|
+
debug = true
|
43
|
+
elsif arg.include? "-p"
|
44
|
+
profiler = true
|
45
|
+
unless have_library("profiler", "ProfilerStart")
|
46
|
+
message "'libprofiler' could not be found.\n"
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if CONFIG['GCC'] == 'yes'
|
53
|
+
if debug
|
54
|
+
flags = "--coverage -g3 -fprofile-arcs -ftest-coverage"
|
55
|
+
message "!! set #{flags} for coverage !!"
|
56
|
+
$CFLAGS += " #{flags}"
|
57
|
+
$DLDFLAGS += " #{flags}"
|
58
|
+
$LIBS += " -lgcov"
|
59
|
+
end
|
60
|
+
if profiler
|
61
|
+
message "Linking to profiler library\n"
|
62
|
+
pkg_config('profiler')
|
63
|
+
$LIBS += " -lprofiler"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
message "=== Checking Ruby features ===\n"
|
68
|
+
|
69
|
+
have_header("ruby/io.h")
|
70
|
+
have_func("rb_big_pack")
|
71
|
+
have_func("rb_enumeratorize")
|
72
|
+
have_func("rb_str_encode")
|
73
|
+
|
74
|
+
message "=== Checking platform features ===\n"
|
75
|
+
|
76
|
+
have_func("gmtime_r")
|
77
|
+
|
78
|
+
create_header
|
79
|
+
create_makefile("kryptcore")
|
80
|
+
message "Done.\n"
|
@@ -0,0 +1,110 @@
|
|
1
|
+
/*
|
2
|
+
* krypt-core API - C implementation
|
3
|
+
*
|
4
|
+
* Copyright (c) 2011-2013
|
5
|
+
* Hiroshi Nakamura <nahi@ruby-lang.org>
|
6
|
+
* Martin Bosslet <martin.bosslet@gmail.com>
|
7
|
+
* All rights reserved.
|
8
|
+
*
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
* a copy of this software and associated documentation files (the
|
11
|
+
* "Software"), to deal in the Software without restriction, including
|
12
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
15
|
+
* the following conditions:
|
16
|
+
*
|
17
|
+
* The above copyright notice and this permission notice shall be
|
18
|
+
* included in all copies or substantial portions of the Software.
|
19
|
+
*
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
24
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
25
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
26
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
*/
|
28
|
+
|
29
|
+
#include "krypt-core.h"
|
30
|
+
|
31
|
+
VALUE mKrypt;
|
32
|
+
VALUE eKryptError;
|
33
|
+
|
34
|
+
ID sKrypt_ID_TO_DER, sKrypt_ID_TO_PEM;
|
35
|
+
ID sKrypt_ID_EACH;
|
36
|
+
ID sKrypt_ID_EQUALS;
|
37
|
+
ID sKrypt_ID_SORT_BANG, sKrypt_ID_SORT;
|
38
|
+
|
39
|
+
VALUE
|
40
|
+
krypt_to_der(VALUE obj)
|
41
|
+
{
|
42
|
+
VALUE tmp;
|
43
|
+
|
44
|
+
tmp = rb_funcall(obj, sKrypt_ID_TO_DER, 0);
|
45
|
+
StringValue(tmp);
|
46
|
+
|
47
|
+
return tmp;
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE
|
51
|
+
krypt_to_der_if_possible(VALUE obj)
|
52
|
+
{
|
53
|
+
if(rb_respond_to(obj, sKrypt_ID_TO_DER))
|
54
|
+
return krypt_to_der(obj);
|
55
|
+
return obj;
|
56
|
+
}
|
57
|
+
|
58
|
+
VALUE
|
59
|
+
krypt_to_pem(VALUE obj)
|
60
|
+
{
|
61
|
+
VALUE tmp;
|
62
|
+
|
63
|
+
tmp = rb_funcall(obj, sKrypt_ID_TO_PEM, 0);
|
64
|
+
StringValue(tmp);
|
65
|
+
|
66
|
+
return tmp;
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE
|
70
|
+
krypt_to_pem_if_possible(VALUE obj)
|
71
|
+
{
|
72
|
+
if(rb_respond_to(obj, sKrypt_ID_TO_PEM))
|
73
|
+
return krypt_to_pem(obj);
|
74
|
+
return obj;
|
75
|
+
}
|
76
|
+
|
77
|
+
void
|
78
|
+
krypt_compute_twos_complement(uint8_t *dest, uint8_t *src, size_t len)
|
79
|
+
{
|
80
|
+
size_t i;
|
81
|
+
|
82
|
+
for (i=0; i<len; ++i) {
|
83
|
+
dest[i] = ~src[i];
|
84
|
+
}
|
85
|
+
while (dest[i - 1] == 0xff) {
|
86
|
+
dest[i - 1] = 0x0;
|
87
|
+
i--;
|
88
|
+
}
|
89
|
+
dest[i-1]++;
|
90
|
+
}
|
91
|
+
|
92
|
+
void
|
93
|
+
Init_kryptcore(void)
|
94
|
+
{
|
95
|
+
mKrypt = rb_path2class("Krypt");
|
96
|
+
eKryptError = rb_path2class("Krypt::Error");
|
97
|
+
|
98
|
+
sKrypt_ID_TO_DER = rb_intern("to_der");
|
99
|
+
sKrypt_ID_TO_PEM = rb_intern("to_pem");
|
100
|
+
sKrypt_ID_EACH = rb_intern("each");
|
101
|
+
sKrypt_ID_EQUALS = rb_intern("==");
|
102
|
+
sKrypt_ID_SORT_BANG = rb_intern("sort!");
|
103
|
+
sKrypt_ID_SORT = rb_intern("sort");
|
104
|
+
|
105
|
+
/* Init components */
|
106
|
+
Init_krypt_io();
|
107
|
+
Init_krypt_asn1();
|
108
|
+
Init_krypt_native_provider();
|
109
|
+
Init_krypt_digest();
|
110
|
+
}
|