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,117 @@
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_ASN1_INTERNAL_H_)
30
+ #define _KRYPT_ASN1_INTERNAL_H_
31
+
32
+ #define CHAR_BIT_MINUS_ONE (CHAR_BIT - 1)
33
+
34
+ #define CONSTRUCTED_MASK 0x20
35
+ #define COMPLEX_TAG_MASK 0x1f
36
+ #define INFINITE_LENGTH_MASK 0x80
37
+
38
+ #define TAG_CLASS_UNIVERSAL 0x00
39
+ #define TAG_CLASS_APPLICATION 0x40
40
+ #define TAG_CLASS_CONTEXT_SPECIFIC 0x80
41
+ #define TAG_CLASS_PRIVATE 0xc0
42
+
43
+ #define TAGS_END_OF_CONTENTS 0x00
44
+ #define TAGS_BOOLEAN 0x01
45
+ #define TAGS_INTEGER 0x02
46
+ #define TAGS_BIT_STRING 0x03
47
+ #define TAGS_OCTET_STRING 0x04
48
+ #define TAGS_NULL 0x05
49
+ #define TAGS_OBJECT_ID 0x06
50
+ #define TAGS_ENUMERATED 0x0a
51
+ #define TAGS_UTF8_STRING 0x0c
52
+ #define TAGS_SEQUENCE 0x10
53
+ #define TAGS_SET 0x11
54
+ #define TAGS_NUMERIC_STRING 0x12
55
+ #define TAGS_PRINTABLE_STRING 0x13
56
+ #define TAGS_T61_STRING 0x14
57
+ #define TAGS_VIDEOTEX_STRING 0x15
58
+ #define TAGS_IA5_STRING 0x16
59
+ #define TAGS_UTC_TIME 0x17
60
+ #define TAGS_GENERALIZED_TIME 0x18
61
+ #define TAGS_GRAPHIC_STRING 0x19
62
+ #define TAGS_ISO64_STRING 0x1a
63
+ #define TAGS_GENERAL_STRING 0x1b
64
+ #define TAGS_UNIVERSAL_STRING 0x1c
65
+ #define TAGS_BMP_STRING 0x1e
66
+
67
+ typedef struct krypt_asn1_header_st {
68
+ int tag;
69
+ int tag_class;
70
+ int is_constructed;
71
+ int is_infinite;
72
+ size_t length;
73
+ uint8_t *tag_bytes;
74
+ size_t tag_len;
75
+ uint8_t *length_bytes;
76
+ size_t length_len;
77
+ } krypt_asn1_header;
78
+
79
+ typedef struct krypt_asn1_object_st {
80
+ krypt_asn1_header *header;
81
+ uint8_t *bytes;
82
+ size_t bytes_len;
83
+ } krypt_asn1_object;
84
+
85
+ typedef int (*krypt_asn1_decoder)(VALUE self, uint8_t *bytes, size_t len, VALUE *out);
86
+ typedef int (*krypt_asn1_encoder)(VALUE self, VALUE value, uint8_t **out, size_t *len);
87
+ typedef int (*krypt_asn1_validator)(VALUE, VALUE);
88
+
89
+ typedef struct krypt_asn1_codec_st {
90
+ krypt_asn1_encoder encoder;
91
+ krypt_asn1_decoder decoder;
92
+ krypt_asn1_validator validator;
93
+ } krypt_asn1_codec;
94
+
95
+ extern krypt_asn1_codec KRYPT_DEFAULT_CODEC;
96
+ extern krypt_asn1_codec krypt_asn1_codecs[];
97
+
98
+ krypt_asn1_header *krypt_asn1_header_new(void);
99
+ void krypt_asn1_header_free(krypt_asn1_header *header);
100
+ krypt_asn1_object *krypt_asn1_object_new(krypt_asn1_header *header);
101
+ krypt_asn1_object *krypt_asn1_object_new_value(krypt_asn1_header *header, uint8_t *value, size_t len);
102
+ void krypt_asn1_object_free(krypt_asn1_object *object);
103
+
104
+ ID krypt_asn1_tag_class_for_int(int tag_class);
105
+ int krypt_asn1_tag_class_for_id(ID tag_class);
106
+ int krypt_asn1_next_header(binyo_instream *in, krypt_asn1_header **out);
107
+ int krypt_asn1_skip_value(binyo_instream *in, krypt_asn1_header *last);
108
+ int krypt_asn1_get_value(binyo_instream *in, krypt_asn1_header *last, uint8_t **out, size_t *outlen);
109
+ binyo_instream *krypt_asn1_get_value_stream(binyo_instream *in, krypt_asn1_header *last, int values_only);
110
+
111
+ int krypt_asn1_header_encode(binyo_outstream *out, krypt_asn1_header *header);
112
+ int krypt_asn1_object_encode(binyo_outstream *out, krypt_asn1_object *object);
113
+
114
+ int krypt_asn1_cmp_set_of(uint8_t *s1, size_t len1, uint8_t *s2, size_t len2, int *result);
115
+
116
+ #endif /* _KRYPT_ASN1_INTERNAL_H_ */
117
+