krypt-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/LICENSE +20 -0
  2. data/ext/krypt/core/Makefile +221 -0
  3. data/ext/krypt/core/binyo-error.h +40 -0
  4. data/ext/krypt/core/binyo-io-buffer.h +54 -0
  5. data/ext/krypt/core/binyo-io.h +131 -0
  6. data/ext/krypt/core/extconf.h +8 -0
  7. data/ext/krypt/core/extconf.rb +80 -0
  8. data/ext/krypt/core/krypt-core.c +110 -0
  9. data/ext/krypt/core/krypt-core.h +97 -0
  10. data/ext/krypt/core/krypt-core.o +0 -0
  11. data/ext/krypt/core/krypt-provider.h +86 -0
  12. data/ext/krypt/core/krypt_asn1-internal.c +681 -0
  13. data/ext/krypt/core/krypt_asn1-internal.h +117 -0
  14. data/ext/krypt/core/krypt_asn1-internal.o +0 -0
  15. data/ext/krypt/core/krypt_asn1.c +2109 -0
  16. data/ext/krypt/core/krypt_asn1.h +88 -0
  17. data/ext/krypt/core/krypt_asn1.o +0 -0
  18. data/ext/krypt/core/krypt_asn1_codec.c +973 -0
  19. data/ext/krypt/core/krypt_asn1_codec.o +0 -0
  20. data/ext/krypt/core/krypt_asn1_in_adapter.c +178 -0
  21. data/ext/krypt/core/krypt_asn1_in_adapter.o +0 -0
  22. data/ext/krypt/core/krypt_asn1_in_chunked.c +292 -0
  23. data/ext/krypt/core/krypt_asn1_in_chunked.o +0 -0
  24. data/ext/krypt/core/krypt_asn1_in_definite.c +156 -0
  25. data/ext/krypt/core/krypt_asn1_in_definite.o +0 -0
  26. data/ext/krypt/core/krypt_asn1_parser.c +592 -0
  27. data/ext/krypt/core/krypt_asn1_parser.o +0 -0
  28. data/ext/krypt/core/krypt_asn1_template-internal.h +185 -0
  29. data/ext/krypt/core/krypt_asn1_template.c +459 -0
  30. data/ext/krypt/core/krypt_asn1_template.h +56 -0
  31. data/ext/krypt/core/krypt_asn1_template.o +0 -0
  32. data/ext/krypt/core/krypt_asn1_template_encoder.c +76 -0
  33. data/ext/krypt/core/krypt_asn1_template_encoder.o +0 -0
  34. data/ext/krypt/core/krypt_asn1_template_parser.c +1176 -0
  35. data/ext/krypt/core/krypt_asn1_template_parser.o +0 -0
  36. data/ext/krypt/core/krypt_b64-internal.h +38 -0
  37. data/ext/krypt/core/krypt_b64.c +391 -0
  38. data/ext/krypt/core/krypt_b64.h +41 -0
  39. data/ext/krypt/core/krypt_b64.o +0 -0
  40. data/ext/krypt/core/krypt_digest.c +391 -0
  41. data/ext/krypt/core/krypt_digest.h +51 -0
  42. data/ext/krypt/core/krypt_digest.o +0 -0
  43. data/ext/krypt/core/krypt_error.c +221 -0
  44. data/ext/krypt/core/krypt_error.h +46 -0
  45. data/ext/krypt/core/krypt_error.o +0 -0
  46. data/ext/krypt/core/krypt_hex-internal.h +36 -0
  47. data/ext/krypt/core/krypt_hex.c +255 -0
  48. data/ext/krypt/core/krypt_hex.h +41 -0
  49. data/ext/krypt/core/krypt_hex.o +0 -0
  50. data/ext/krypt/core/krypt_io.c +65 -0
  51. data/ext/krypt/core/krypt_io.h +56 -0
  52. data/ext/krypt/core/krypt_io.o +0 -0
  53. data/ext/krypt/core/krypt_io_in_pem.c +397 -0
  54. data/ext/krypt/core/krypt_io_in_pem.o +0 -0
  55. data/ext/krypt/core/krypt_missing.c +238 -0
  56. data/ext/krypt/core/krypt_missing.h +62 -0
  57. data/ext/krypt/core/krypt_missing.o +0 -0
  58. data/ext/krypt/core/krypt_pem.c +171 -0
  59. data/ext/krypt/core/krypt_pem.o +0 -0
  60. data/ext/krypt/core/krypt_provider-internal.h +40 -0
  61. data/ext/krypt/core/krypt_provider.c +136 -0
  62. data/ext/krypt/core/krypt_provider.o +0 -0
  63. data/ext/krypt/core/kryptcore.so +0 -0
  64. data/ext/krypt/core/mkmf.log +130 -0
  65. data/lib/krypt-core/version.rb +3 -0
  66. data/lib/krypt-core.rb +35 -0
  67. data/lib/kryptcore.so +0 -0
  68. data/spec/README +2 -0
  69. data/test/README +2 -0
  70. data/test/res/certificate.cer +0 -0
  71. data/test/resources.rb +48 -0
  72. data/test/scratch.rb +17 -0
  73. metadata +150 -0
@@ -0,0 +1,171 @@
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 mKryptPEM;
32
+ VALUE eKryptPEMError;
33
+
34
+ static int
35
+ int_consume_stream(binyo_instream *in, VALUE *vout)
36
+ {
37
+ binyo_outstream *out;
38
+ size_t len;
39
+ uint8_t *str;
40
+ uint8_t buf[BINYO_IO_BUF_SIZE];
41
+ ssize_t read;
42
+
43
+ out = binyo_outstream_new_bytes_size(BINYO_IO_BUF_SIZE);
44
+
45
+ while ((read = binyo_instream_read(in, buf, BINYO_IO_BUF_SIZE)) >= 0) {
46
+ binyo_outstream_write(out, buf, read);
47
+ }
48
+ if (read == BINYO_ERR) {
49
+ binyo_outstream_free(out);
50
+ return KRYPT_ERR;
51
+ }
52
+
53
+ len = binyo_outstream_bytes_get_bytes_free(out, &str);
54
+ if (len == 0) {
55
+ *vout = Qnil;
56
+ } else {
57
+ *vout = rb_str_new((const char*)str, len);
58
+ xfree(str);
59
+ }
60
+ return KRYPT_OK;
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * Krypt::PEM.decode(data) { |der, name, i| block } -> Array
66
+ *
67
+ * +data+ can be either a PEM-encoded String, an IO-like object that features
68
+ * a +read+ method or any arbitrary object that has a +to_pem+ method returning
69
+ * either a String or an IO-like object.
70
+ *
71
+ * Returns an Array that contains the DER-encoded results in the order they
72
+ * were decoded. PEM data can potentially consist of multiple elements, a
73
+ * common example being 'trusted certificate bundles' that contain a set of
74
+ * to-be-trusted certificates.
75
+ *
76
+ * If additionally a block is given, +block+ is called for each element that is
77
+ * decoded, where +der+ contains the decoded element, +name+ the identifier of
78
+ * the current element (e.g. 'CERTIFICATE') and +i+ the index of the current
79
+ * element starting with 0.
80
+ *
81
+ * === Example: Decoding a simple certificate file
82
+ *
83
+ * File.open("certificate.pem", "rb") do |f|
84
+ * cert = Krypt::PEM.decode(f)[0]
85
+ * # process the certificate
86
+ * end
87
+ *
88
+ * === Example: Decoding multiple elements contained in one file
89
+ *
90
+ * File.open("trusted-certs.pem", "rb") do |f|
91
+ * Krypt::PEM.decode(f) do |der, name, i|
92
+ * puts "Element #{i}: #{name}"
93
+ * File.open("cert-#{i}.der", "wb") do |g|
94
+ * g.print der
95
+ * end
96
+ * end
97
+ * end
98
+ */
99
+ static VALUE
100
+ krypt_pem_decode(VALUE self, VALUE pem)
101
+ {
102
+ VALUE ary, der;
103
+ size_t i = 0;
104
+ int result;
105
+ binyo_instream *in = krypt_instream_new_pem(krypt_instream_new_value_pem(pem));
106
+
107
+ ary = rb_ary_new();
108
+
109
+ while ((result = int_consume_stream(in, &der)) == KRYPT_OK) {
110
+ if (NIL_P(der))
111
+ break;
112
+
113
+ rb_ary_push(ary, der);
114
+ if(rb_block_given_p()) {
115
+ uint8_t *name;
116
+ size_t len;
117
+ VALUE vname;
118
+ if (krypt_pem_get_last_name(in, &name, &len) == BINYO_ERR) goto error;
119
+ vname = rb_str_new((const char *) name, len);
120
+ xfree(name);
121
+ rb_yield_values(3, der, vname, LONG2NUM(i++));
122
+ }
123
+ krypt_pem_continue_stream(in);
124
+ }
125
+ if (result == KRYPT_ERR) goto error;
126
+
127
+ binyo_instream_free(in);
128
+ return ary;
129
+
130
+ error:
131
+ binyo_instream_free(in);
132
+ krypt_error_raise(eKryptPEMError, "Error while decoding PEM data");
133
+ return Qnil;
134
+ }
135
+
136
+ void
137
+ Init_krypt_pem(void)
138
+ {
139
+ #if 0
140
+ mKrypt = rb_define_module("Krypt"); /* Let RDoc know */
141
+ #endif
142
+
143
+ /* Document-module: Krypt::PEM
144
+ *
145
+ * The popular PEM format is essentially the Base64 encoding of some
146
+ * DER-encoded data, with additional "header" and "footer" lines
147
+ * indicating the type of data being encoded. The PEM module offers
148
+ * ways to conveniently encode and decode arbitrary PEM-formatted
149
+ * data.
150
+ *
151
+ * === Converting from PEM to DER
152
+ *
153
+ * PEM-encoded data can be easily converted to equivalent DER-encoded
154
+ * data:
155
+ *
156
+ * pem = File.read("data.pem")
157
+ * File.open("data.der", "wb") do |f|
158
+ * f.print(Krypt::PEM.decode(pem))
159
+ * end
160
+ */
161
+ mKryptPEM = rb_define_module_under(mKrypt, "PEM");
162
+ rb_define_module_function(mKryptPEM, "decode", krypt_pem_decode, 1);
163
+
164
+ /* Document-class: Krypt::PEM::PEMError
165
+ *
166
+ * Generic error class for all errors raised while writing to or reading
167
+ * from a stream with PEM data.
168
+ */
169
+ eKryptPEMError = rb_define_class_under(mKryptPEM, "PEMError", eKryptError);
170
+ }
171
+
Binary file
@@ -0,0 +1,40 @@
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
+ #ifndef _KRYPT_PROVIDER_INTERNAL_H_
30
+ #define _KRYPT_PROVIDER_INTERNAL_H_
31
+
32
+ extern VALUE mKryptProvider;
33
+ extern VALUE cKryptNativeProvider;
34
+
35
+ /* Implements the boilerplate to connect the native provider to Ruby world */
36
+ VALUE krypt_native_provider_new(krypt_provider *provider);
37
+
38
+ void Init_krypt_native_provider(void);
39
+
40
+ #endif /* _KRYPT_PROVIDER_INTERNAL_H_ */
@@ -0,0 +1,136 @@
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 mKryptProvider;
32
+ VALUE cKryptNativeProvider;
33
+
34
+ static ID sKrypt_ID_register, sKrypt_ID_new_service;
35
+
36
+ static void
37
+ int_krypt_native_provider_mark(krypt_provider *provider)
38
+ {
39
+ if (!provider) return;
40
+
41
+ /*TODO*/
42
+ }
43
+
44
+ static void
45
+ int_krypt_native_provider_free(krypt_provider *provider)
46
+ {
47
+ if (!provider) return;
48
+
49
+ /*TODO*/
50
+ }
51
+
52
+ #define int_krypt_native_provider_set(klass, obj, provider) \
53
+ do { \
54
+ if (!(provider)) { \
55
+ rb_raise(eKryptError, "Uninitialized Provider"); \
56
+ } \
57
+ (obj) = Data_Wrap_Struct((klass), int_krypt_native_provider_mark, int_krypt_native_provider_free, (provider)); \
58
+ } while (0)
59
+
60
+ #define int_krypt_native_provider_get(obj, provider) \
61
+ do { \
62
+ Data_Get_Struct((obj), krypt_provider, (provider)); \
63
+ if (!(provider)) { \
64
+ rb_raise(eKryptError, "Uninitialized Provider"); \
65
+ } \
66
+ } while (0)
67
+
68
+ VALUE
69
+ krypt_native_provider_new(krypt_provider *provider)
70
+ {
71
+ VALUE obj;
72
+ int_krypt_native_provider_set(cKryptNativeProvider, obj, provider);
73
+ return obj;
74
+ }
75
+
76
+ static VALUE
77
+ int_provider_digest_new(krypt_provider *provider, VALUE aryargs)
78
+ {
79
+ VALUE vname_or_oid;
80
+ const char *name_or_oid;
81
+ krypt_md *md;
82
+
83
+ if (NIL_P(aryargs)) return Qnil;
84
+ vname_or_oid = rb_ary_entry(aryargs, 0);
85
+ name_or_oid = StringValueCStr(vname_or_oid);
86
+ if ((md = krypt_md_new(provider, name_or_oid))) {
87
+ return krypt_digest_new(md);
88
+ }
89
+ return Qnil;
90
+ }
91
+
92
+ static VALUE
93
+ krypt_native_provider_new_service(int argc, VALUE *argv, VALUE self)
94
+ {
95
+ VALUE service_class;
96
+ VALUE rest = Qnil;
97
+ krypt_provider *provider;
98
+
99
+ rb_scan_args(argc, argv, "1*", &service_class, &rest);
100
+ int_krypt_native_provider_get(self, provider);
101
+
102
+ if (service_class == mKryptDigest) {
103
+ return int_provider_digest_new(provider, rest);
104
+ }
105
+
106
+ return Qnil;
107
+ }
108
+
109
+ void
110
+ krypt_provider_register(krypt_provider *provider)
111
+ {
112
+ VALUE rb_provider;
113
+ if (!provider->name) rb_raise(eKryptError, "Provider must have a name");
114
+
115
+ rb_provider = krypt_native_provider_new(provider);
116
+ rb_funcall(mKryptProvider, sKrypt_ID_register, 2, rb_str_new2(provider->name), rb_provider);
117
+ }
118
+
119
+ void
120
+ Init_krypt_native_provider(void)
121
+ {
122
+ #if 0
123
+ mKrypt = rb_define_module("Krypt"); /* Let RDoc know */
124
+ mKryptProvider = rb_define_module_under(mKrypt, "Provider"); /* Let RDoc know */
125
+ #endif
126
+
127
+ mKryptProvider = rb_path2class("Krypt::Provider");
128
+ sKrypt_ID_register = rb_intern("register");
129
+ sKrypt_ID_new_service = rb_intern("new_service");
130
+
131
+ cKryptNativeProvider = rb_define_class_under(mKryptProvider, "NativeProvider", rb_cObject);
132
+
133
+ rb_define_method(cKryptNativeProvider, "new_service", krypt_native_provider_new_service, -1);
134
+ rb_undef_method(CLASS_OF(cKryptNativeProvider), "new"); /* private constructor */
135
+ }
136
+
Binary file
Binary file
@@ -0,0 +1,130 @@
1
+ have_header: checking for ruby/io.h... -------------------- yes
2
+
3
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include "ruby.h"
7
+ 2:
8
+ 3: int main(void) {return 0;}
9
+ /* end */
10
+
11
+ "gcc -E -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -o conftest.i"
12
+ checked program was:
13
+ /* begin */
14
+ 1: #include "ruby.h"
15
+ 2:
16
+ 3: #include <ruby/io.h>
17
+ /* end */
18
+
19
+ --------------------
20
+
21
+ have_func: checking for rb_big_pack()... -------------------- yes
22
+
23
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
24
+ conftest.c: In function ‘t’:
25
+ conftest.c:6:32: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
26
+ checked program was:
27
+ /* begin */
28
+ 1: #include "ruby.h"
29
+ 2:
30
+ 3: /*top*/
31
+ 4: int main(void) {return 0;}
32
+ 5: extern int t(void);
33
+ 6: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_big_pack; return 0; }
34
+ /* end */
35
+
36
+ --------------------
37
+
38
+ have_func: checking for rb_enumeratorize()... -------------------- yes
39
+
40
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
41
+ conftest.c: In function ‘t’:
42
+ conftest.c:6:32: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
43
+ checked program was:
44
+ /* begin */
45
+ 1: #include "ruby.h"
46
+ 2:
47
+ 3: /*top*/
48
+ 4: int main(void) {return 0;}
49
+ 5: extern int t(void);
50
+ 6: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_enumeratorize; return 0; }
51
+ /* end */
52
+
53
+ --------------------
54
+
55
+ have_func: checking for rb_str_encode()... -------------------- yes
56
+
57
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
58
+ conftest.c: In function ‘t’:
59
+ conftest.c:6:57: error: ‘rb_str_encode’ undeclared (first use in this function)
60
+ conftest.c:6:57: note: each undeclared identifier is reported only once for each function it appears in
61
+ conftest.c:6:32: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
62
+ checked program was:
63
+ /* begin */
64
+ 1: #include "ruby.h"
65
+ 2:
66
+ 3: /*top*/
67
+ 4: int main(void) {return 0;}
68
+ 5: extern int t(void);
69
+ 6: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_str_encode; return 0; }
70
+ /* end */
71
+
72
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
73
+ conftest.c: In function ‘t’:
74
+ conftest.c:6:1: warning: implicit declaration of function ‘rb_str_encode’ [-Wimplicit-function-declaration]
75
+ checked program was:
76
+ /* begin */
77
+ 1: #include "ruby.h"
78
+ 2:
79
+ 3: /*top*/
80
+ 4: int main(void) {return 0;}
81
+ 5: extern int t(void);
82
+ 6: int t(void) { rb_str_encode(); return 0; }
83
+ /* end */
84
+
85
+ --------------------
86
+
87
+ have_func: checking for gmtime_r()... -------------------- yes
88
+
89
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
90
+ conftest.c: In function ‘t’:
91
+ conftest.c:6:57: error: ‘gmtime_r’ undeclared (first use in this function)
92
+ conftest.c:6:57: note: each undeclared identifier is reported only once for each function it appears in
93
+ conftest.c:6:32: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
94
+ checked program was:
95
+ /* begin */
96
+ 1: #include "ruby.h"
97
+ 2:
98
+ 3: /*top*/
99
+ 4: int main(void) {return 0;}
100
+ 5: extern int t(void);
101
+ 6: int t(void) { void ((*volatile p)()); p = (void ((*)()))gmtime_r; return 0; }
102
+ /* end */
103
+
104
+ "gcc -o conftest -I/home/martin/ruby/include/ruby-2.0.0/x86_64-linux -I/home/martin/ruby/include/ruby-2.0.0/ruby/backward -I/home/martin/ruby/include/ruby-2.0.0 -I. -O3 -fno-fast-math -ggdb3 -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 conftest.c -L. -L/home/martin/ruby/lib -Wl,-R/home/martin/ruby/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/martin/ruby/lib -L/home/martin/ruby/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
105
+ conftest.c: In function ‘t’:
106
+ conftest.c:6:1: warning: implicit declaration of function ‘gmtime_r’ [-Wimplicit-function-declaration]
107
+ checked program was:
108
+ /* begin */
109
+ 1: #include "ruby.h"
110
+ 2:
111
+ 3: /*top*/
112
+ 4: int main(void) {return 0;}
113
+ 5: extern int t(void);
114
+ 6: int t(void) { gmtime_r(); return 0; }
115
+ /* end */
116
+
117
+ --------------------
118
+
119
+ extconf.h is:
120
+ /* begin */
121
+ 1: #ifndef EXTCONF_H
122
+ 2: #define EXTCONF_H
123
+ 3: #define HAVE_RUBY_IO_H 1
124
+ 4: #define HAVE_RB_BIG_PACK 1
125
+ 5: #define HAVE_RB_ENUMERATORIZE 1
126
+ 6: #define HAVE_RB_STR_ENCODE 1
127
+ 7: #define HAVE_GMTIME_R 1
128
+ 8: #endif
129
+ /* end */
130
+
@@ -0,0 +1,3 @@
1
+ class Krypt
2
+ CORE_VERSION = '0.0.1'
3
+ end
data/lib/krypt-core.rb ADDED
@@ -0,0 +1,35 @@
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 'binyo'
34
+ require 'kryptcore.so'
35
+ require 'krypt-provider-openssl'
data/lib/kryptcore.so ADDED
Binary file
data/spec/README ADDED
@@ -0,0 +1,2 @@
1
+ Specs for krypt-core are to be found in the main krypt project at https://github.com/emboss/krypt.
2
+
data/test/README ADDED
@@ -0,0 +1,2 @@
1
+ Tests for krypt-core are to be found in the main krypt project at https://github.com/emboss/krypt.
2
+
Binary file
data/test/resources.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'openssl'
2
+
3
+ module Resources
4
+
5
+ CERTIFICATE = OpenSSL::X509::Certificate.new <<-_EOF_
6
+ -----BEGIN CERTIFICATE-----
7
+ MIIDPTCCAiWgAwIBAgIBAzANBgkqhkiG9w0BAQQFADA9MRMwEQYKCZImiZPyLGQB
8
+ GRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQDDAJDQTAe
9
+ Fw0xMTEwMjkxNTM2MzJaFw0xMTEwMjkxNjA2MzJaMD4xEzARBgoJkiaJk/IsZAEZ
10
+ FgNvcmcxGTAXBgoJkiaJk/IsZAEZFglydWJ5LWxhbmcxDDAKBgNVBAMMA0VFMjCB
11
+ nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAy8LEsNRApz7U/j5DoB4XBgO9Z8At
12
+ v5y/OVQRp0ag8Tqo1YewsWijxEWB7JOATwpBN267U4T1nPZIxxEEO7n/WNa2ws9J
13
+ Wsjah8ssEBFSxZqdXKSLf0N4Hi7/GQ/aYoaMCiQ8jA4jegK2FJmXM71uPe+jFN/p
14
+ eeBOpRfyXxRFOYcCAwEAAaOByjCBxzAOBgNVHQ8BAf8EBAMCBeAwHQYDVR0OBBYE
15
+ FNH++fv4rhvBYMv6A+JZbdhzCJITME8GA1UdIwRIMEahQaQ/MD0xEzARBgoJkiaJ
16
+ k/IsZAEZFgNvcmcxGTAXBgoJkiaJk/IsZAEZFglydWJ5LWxhbmcxCzAJBgNVBAMM
17
+ AkNBggEBMCcGA1UdJQQgMB4GCCsGAQUFBwMCBggrBgEFBQcDBAYIKwYBBQUHAwMw
18
+ HAYDVR0RBBUwE4ERZWUyQHJ1YnktbGFuZy5vcmcwDQYJKoZIhvcNAQEEBQADggEB
19
+ ABLJKAS9nXFI3idP3dXXs8n4gLBrWHyaacklwnj8gvVoNtYQIICXODY/zQLtzfjx
20
+ SQxlrOUtn0uYTzJUNc+NLfc8EzcVDhmSWhq+msCFEyhL5+kBceFj2ZI8f9OuQ87m
21
+ zy1yqE1jxP1fsGDZ3Cqny86jJvwRzPW6NkPtkFzS6ZYe09DXDZnUuZP8kVpn4Pit
22
+ vHmj/XVKl4LGxlrebReqIn+m2K46uxUkQEDhk7R16SAl6N92W7vI/lXr98aVdfF4
23
+ Ozmrzopvt+XbjtvJztDNhpG0G/celhgAOzNx/eq3wl89qHIa+9vvVbFZ0BdYUHai
24
+ z+64/9KqwBAeA66J6k7l7C0=
25
+ -----END CERTIFICATE-----
26
+ _EOF_
27
+
28
+ class << self
29
+ def certificate
30
+ CERTIFICATE.to_der
31
+ end
32
+
33
+ def certificate_io
34
+ File.new(File.expand_path('res/certificate.cer', File.dirname(__FILE__)))
35
+ end
36
+
37
+ def bytes_to_io(str)
38
+ raw = [str.join('')].pack('H*')
39
+ StringIO.new raw
40
+ end
41
+
42
+ def bytes(str)
43
+ [str.join('')].pack('H*')
44
+ end
45
+ end
46
+
47
+ end
48
+
data/test/scratch.rb ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'krypt'
4
+ require_relative 'resources'
5
+ require 'stringio'
6
+ require 'pp'
7
+ require 'openssl'
8
+ require 'base64'
9
+ require 'benchmark'
10
+
11
+ p Krypt::Provider::PROVIDERS
12
+
13
+ d = Krypt::Digest.new("SHA1")
14
+ p d
15
+
16
+ result = d.hexdigest("test")
17
+ p result