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.
- 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
@@ -0,0 +1,97 @@
|
|
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
|
+
#if !defined(_KRYPT_CORE_H_)
|
30
|
+
#define _KRYPT_CORE_H_
|
31
|
+
|
32
|
+
#include RUBY_EXTCONF_H
|
33
|
+
|
34
|
+
#if defined(__cplusplus)
|
35
|
+
extern "C" {
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#define RSTRING_NOT_MODIFIED 1
|
39
|
+
#define RUBY_READONLY_STRING 1
|
40
|
+
|
41
|
+
#include <ruby.h>
|
42
|
+
|
43
|
+
#if defined(HAVE_RUBY_IO_H)
|
44
|
+
#include <ruby/io.h>
|
45
|
+
#endif
|
46
|
+
|
47
|
+
/* This is just a precaution to take remind us of thread safety
|
48
|
+
* issues in case there would be no GVL */
|
49
|
+
#ifndef InitVM
|
50
|
+
#define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();}
|
51
|
+
#endif
|
52
|
+
|
53
|
+
extern VALUE mKrypt;
|
54
|
+
extern VALUE eKryptError;
|
55
|
+
|
56
|
+
extern ID sKrypt_ID_TO_DER;
|
57
|
+
extern ID sKrypt_ID_TO_PEM;
|
58
|
+
extern ID sKrypt_ID_EACH;
|
59
|
+
extern ID sKrypt_ID_EQUALS;
|
60
|
+
extern ID sKrypt_ID_SORT_BANG;
|
61
|
+
extern ID sKrypt_ID_SORT;
|
62
|
+
|
63
|
+
/** krypt-provider interface */
|
64
|
+
#include "krypt-provider.h"
|
65
|
+
#include "krypt_provider-internal.h"
|
66
|
+
|
67
|
+
/** krypt-core headers **/
|
68
|
+
#include "krypt_error.h"
|
69
|
+
#include "krypt_missing.h"
|
70
|
+
#include "krypt_io.h"
|
71
|
+
#include "krypt_asn1.h"
|
72
|
+
#include "krypt_asn1_template.h"
|
73
|
+
#include "krypt_digest.h"
|
74
|
+
|
75
|
+
VALUE krypt_to_der_if_possible(VALUE obj);
|
76
|
+
VALUE krypt_to_der(VALUE obj);
|
77
|
+
VALUE krypt_to_pem_if_possible(VALUE obj);
|
78
|
+
VALUE krypt_to_pem(VALUE obj);
|
79
|
+
|
80
|
+
/* internal Base64 en-/decoder */
|
81
|
+
#include "krypt_b64-internal.h"
|
82
|
+
|
83
|
+
/* internal hex en-/decoder */
|
84
|
+
#include "krypt_hex-internal.h"
|
85
|
+
|
86
|
+
/* helper for integer encoding/decoding */
|
87
|
+
void krypt_compute_twos_complement(uint8_t *dest, uint8_t *src, size_t len);
|
88
|
+
|
89
|
+
void Init_kryptcore(void);
|
90
|
+
|
91
|
+
#if defined(__cplusplus)
|
92
|
+
}
|
93
|
+
#endif
|
94
|
+
|
95
|
+
#endif /* _KRYPT_CORE_H_ */
|
96
|
+
|
97
|
+
|
Binary file
|
@@ -0,0 +1,86 @@
|
|
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_H_
|
30
|
+
#define _KRYPT_PROVIDER_H_
|
31
|
+
|
32
|
+
|
33
|
+
#ifndef _RSTRING_NOT_MODIFIED
|
34
|
+
#define RSTRING_NOT_MODIFIED 1
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#ifndef RUBY_READONLY_STRING
|
38
|
+
#define RUBY_READONLY_STRING 1
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#include <ruby.h>
|
42
|
+
|
43
|
+
#ifndef KRYPT_OK
|
44
|
+
#define KRYPT_OK 1
|
45
|
+
#endif
|
46
|
+
#ifndef KRYPT_ERR
|
47
|
+
#define KRYPT_ERR -1
|
48
|
+
#endif
|
49
|
+
|
50
|
+
typedef struct krypt_provider_st krypt_provider;
|
51
|
+
|
52
|
+
/* Message digest */
|
53
|
+
typedef struct krypt_interface_md_st krypt_interface_md;
|
54
|
+
|
55
|
+
typedef struct krypt_md_st {
|
56
|
+
krypt_provider *provider;
|
57
|
+
krypt_interface_md *methods;
|
58
|
+
} krypt_md;
|
59
|
+
|
60
|
+
struct krypt_interface_md_st {
|
61
|
+
int (*md_reset)(krypt_md *md);
|
62
|
+
int (*md_update)(krypt_md *md, const void *data, size_t len);
|
63
|
+
int (*md_final)(krypt_md *md, uint8_t ** digest, size_t *len);
|
64
|
+
int (*md_digest)(krypt_md *md, const uint8_t *data, size_t len, uint8_t **digest, size_t *digest_len);
|
65
|
+
int (*md_digest_length)(krypt_md *md, size_t *len);
|
66
|
+
int (*md_block_length)(krypt_md *md, size_t *block_len);
|
67
|
+
int (*md_name)(krypt_md *md, const char **name);
|
68
|
+
void (*mark)(krypt_md *md);
|
69
|
+
void (*free)(krypt_md *md);
|
70
|
+
};
|
71
|
+
|
72
|
+
/* Provider */
|
73
|
+
struct krypt_provider_st {
|
74
|
+
const char *name;
|
75
|
+
krypt_md *(*md_new_oid)(krypt_provider *provider, const char *oid);
|
76
|
+
krypt_md *(*md_new_name)(krypt_provider *provider, const char *name);
|
77
|
+
};
|
78
|
+
|
79
|
+
/* Can be called from within a provider implementation to indicate errors */
|
80
|
+
void krypt_error_add(const char * format, ...);
|
81
|
+
|
82
|
+
/* May be used to register a singleton provider upon initialization */
|
83
|
+
void krypt_provider_register(krypt_provider *provider);
|
84
|
+
|
85
|
+
#endif /* _KRYPT_PROVIDER_H_ */
|
86
|
+
|