krypt 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/README.md +82 -0
- data/lib/krypt.rb +49 -0
- data/lib/krypt/asn1.rb +3 -0
- data/lib/krypt/asn1/common.rb +96 -0
- data/lib/krypt/asn1/template.rb +257 -0
- data/lib/krypt/codec.rb +57 -0
- data/lib/krypt/codec/base64.rb +140 -0
- data/lib/krypt/codec/base_codec.rb +36 -0
- data/lib/krypt/codec/hex.rb +122 -0
- data/lib/krypt/digest.rb +112 -0
- data/lib/krypt/hmac.rb +69 -0
- data/lib/krypt/pkcs5.rb +1 -0
- data/lib/krypt/pkcs5/pbkdf2.rb +41 -0
- data/lib/krypt/provider.rb +35 -0
- data/lib/krypt/x509.rb +3 -0
- data/lib/krypt/x509/certificate.rb +36 -0
- data/lib/krypt/x509/common.rb +41 -0
- data/lib/krypt/x509/crl.rb +33 -0
- data/lib/krypt_missing.rb +32 -0
- data/spec/krypt-core/MEMO.txt +85 -0
- data/spec/krypt-core/asn1/asn1_bit_string_spec.rb +475 -0
- data/spec/krypt-core/asn1/asn1_boolean_spec.rb +392 -0
- data/spec/krypt-core/asn1/asn1_constants_spec.rb +71 -0
- data/spec/krypt-core/asn1/asn1_data_spec.rb +1153 -0
- data/spec/krypt-core/asn1/asn1_end_of_contents_spec.rb +133 -0
- data/spec/krypt-core/asn1/asn1_enumerated_spec.rb +458 -0
- data/spec/krypt-core/asn1/asn1_generalized_time_spec.rb +492 -0
- data/spec/krypt-core/asn1/asn1_integer_spec.rb +557 -0
- data/spec/krypt-core/asn1/asn1_null_spec.rb +360 -0
- data/spec/krypt-core/asn1/asn1_object_id_spec.rb +495 -0
- data/spec/krypt-core/asn1/asn1_octet_string_spec.rb +456 -0
- data/spec/krypt-core/asn1/asn1_parser_spec.rb +503 -0
- data/spec/krypt-core/asn1/asn1_pem_spec.rb +282 -0
- data/spec/krypt-core/asn1/asn1_sequence_spec.rb +637 -0
- data/spec/krypt-core/asn1/asn1_set_spec.rb +795 -0
- data/spec/krypt-core/asn1/asn1_utc_time_spec.rb +495 -0
- data/spec/krypt-core/asn1/asn1_utf8_string_spec.rb +404 -0
- data/spec/krypt-core/asn1/resources.rb +53 -0
- data/spec/krypt-core/base64/base64_spec.rb +97 -0
- data/spec/krypt-core/digest/digest_spec.rb +707 -0
- data/spec/krypt-core/hex/hex_spec.rb +102 -0
- data/spec/krypt-core/pem/pem_decode_spec.rb +235 -0
- data/spec/krypt-core/resources.rb +1 -0
- data/spec/krypt-core/template/template_choice_parse_spec.rb +289 -0
- data/spec/krypt-core/template/template_dsl_spec.rb +351 -0
- data/spec/krypt-core/template/template_seq_of_parse_spec.rb +64 -0
- data/spec/krypt-core/template/template_seq_parse_spec.rb +1241 -0
- data/spec/krypt/codec/base64_decoder_spec.rb +94 -0
- data/spec/krypt/codec/base64_encoder_spec.rb +94 -0
- data/spec/krypt/codec/base64_mixed_spec.rb +16 -0
- data/spec/krypt/codec/hex_decoder_spec.rb +94 -0
- data/spec/krypt/codec/hex_encoder_spec.rb +94 -0
- data/spec/krypt/codec/hex_mixed_spec.rb +17 -0
- data/spec/krypt/codec/identity_shared.rb +119 -0
- data/spec/krypt/hmac/hmac_spec.rb +311 -0
- data/spec/krypt/pkcs5/pbkdf2_spec.rb +79 -0
- data/spec/krypt/provider/provider_spec.rb +83 -0
- data/spec/res/ca-bundle.crt +11758 -0
- data/spec/res/certificate.cer +0 -0
- data/spec/res/certificate.pem +20 -0
- data/spec/res/multiple_certs.pem +60 -0
- data/spec/resources.rb +66 -0
- data/test/helper.rb +8 -0
- data/test/res/certificate.cer +0 -0
- data/test/resources.rb +48 -0
- data/test/scratch.rb +28 -0
- data/test/test_krypt_asn1.rb +119 -0
- data/test/test_krypt_parser.rb +331 -0
- metadata +134 -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.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="http://emboss.github.com/images/krypt-logo.png" alt="krypt" />
|
3
|
+
</p>
|
4
|
+
|
5
|
+
=========
|
6
|
+
[](http://travis-ci.org/krypt/krypt)
|
7
|
+
|
8
|
+
|
9
|
+
krypt. semper pi.
|
10
|
+
-----------------
|
11
|
+
|
12
|
+
The goal of krypt is to provide a platform- and
|
13
|
+
library-independent cryptography API for the Ruby
|
14
|
+
language (http://www.ruby-lang.org). It can be used
|
15
|
+
with all C(++)-based Ruby implementations as well as
|
16
|
+
JRuby.
|
17
|
+
|
18
|
+
The major part of krypt is implemented in Ruby, and it
|
19
|
+
additionally offers the possibility to integrate OS-
|
20
|
+
or language-specific native libraries to implement
|
21
|
+
cryptographic primitives. krypt aims at offering
|
22
|
+
performance while still improving the security and
|
23
|
+
features of the Ruby cryptography infrastructure. Its
|
24
|
+
motto is to keep all the good parts of what exists
|
25
|
+
today and to improve the parts that need improvement.
|
26
|
+
It offers an idiomatic, modern API that cherry-picks
|
27
|
+
the best features of other popular libraries and also
|
28
|
+
offers new features that are not offered by others today.
|
29
|
+
|
30
|
+
|
31
|
+
krypt-core-c
|
32
|
+
------------
|
33
|
+
|
34
|
+
The C implementation of the krypt-core API to be used
|
35
|
+
with all C-based Rubies. The repository can be found at
|
36
|
+
|
37
|
+
https://github.com/krypt/krypt-core-c.
|
38
|
+
|
39
|
+
krypt-core-java
|
40
|
+
---------------
|
41
|
+
|
42
|
+
Realizes the krypt-core API in Java to be used by Jruby
|
43
|
+
(http://www.jruby.org). The repository can be found at
|
44
|
+
|
45
|
+
https://github.com/krypt/krypt-core-java.
|
46
|
+
|
47
|
+
krypt-core-ruby
|
48
|
+
---------------
|
49
|
+
|
50
|
+
An all Ruby implementation of krypt-core. Access to
|
51
|
+
the native krypt-provider libraries is realized via FFI.
|
52
|
+
The repository can be found at
|
53
|
+
|
54
|
+
https://github.com/krypt/krypt-core-ruby.
|
55
|
+
|
56
|
+
krypt-provider-openssl
|
57
|
+
----------------------
|
58
|
+
|
59
|
+
A realization of the krypt-provider API in C that
|
60
|
+
utilizes OpenSSL (http://www.openssl.org). Can also be used
|
61
|
+
by JRuby via krypt-core-ruby and FFI. The repository
|
62
|
+
is at
|
63
|
+
|
64
|
+
https://github.com/krypt/krypt-provider-openssl.
|
65
|
+
|
66
|
+
krypt-provider-jdk
|
67
|
+
------------------
|
68
|
+
|
69
|
+
Realization of the krypt-provider API in Java exclusively
|
70
|
+
to be used by JRuby. The implementation is based on the
|
71
|
+
JDK built-in security and cryptography library. The
|
72
|
+
repository is at
|
73
|
+
|
74
|
+
https://github.com/krypt/krypt-provider-jdk.
|
75
|
+
|
76
|
+
License
|
77
|
+
-------
|
78
|
+
|
79
|
+
Copyright (c) 2012-2013 Hiroshi Nakamura and Martin Boßlet.
|
80
|
+
krypt and all its sub projects are distributed under the MIT
|
81
|
+
License. See LICENSE for further details.
|
82
|
+
|
data/lib/krypt.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
= Info
|
4
|
+
|
5
|
+
krypt - Modern platform- and library-independent cryptography for Ruby
|
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
|
+
module Krypt
|
34
|
+
class Error < StandardError; end
|
35
|
+
end
|
36
|
+
|
37
|
+
require_relative 'krypt_missing'
|
38
|
+
require_relative 'krypt/provider'
|
39
|
+
require_relative 'krypt/digest'
|
40
|
+
require_relative 'krypt/hmac'
|
41
|
+
require_relative 'krypt/pkcs5'
|
42
|
+
|
43
|
+
require 'krypt-core'
|
44
|
+
|
45
|
+
# The following files depend on krypt-core being loaded
|
46
|
+
require_relative 'krypt/asn1'
|
47
|
+
require_relative 'krypt/x509'
|
48
|
+
require_relative 'krypt/codec'
|
49
|
+
|
data/lib/krypt/asn1.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Krypt
|
2
|
+
module ASN1
|
3
|
+
|
4
|
+
class DirectoryString
|
5
|
+
include Template::Choice
|
6
|
+
|
7
|
+
asn1_t61_string
|
8
|
+
asn1_ia5_string
|
9
|
+
asn1_printable_string
|
10
|
+
asn1_universal_string
|
11
|
+
asn1_utf8_string
|
12
|
+
asn1_bmp_string
|
13
|
+
end
|
14
|
+
|
15
|
+
class DistinguishedName
|
16
|
+
include Template::SequenceOf
|
17
|
+
|
18
|
+
class AttributeTypeAndValue
|
19
|
+
include Template::Sequence
|
20
|
+
|
21
|
+
asn1_object_id :type
|
22
|
+
asn1_template :value, DirectoryString
|
23
|
+
end
|
24
|
+
|
25
|
+
class RelativeDistinguishedName
|
26
|
+
include Template::SetOf
|
27
|
+
|
28
|
+
asn1_type AttributeTypeAndValue
|
29
|
+
end
|
30
|
+
|
31
|
+
asn1_type RelativeDistinguishedName
|
32
|
+
end
|
33
|
+
|
34
|
+
class GeneralName
|
35
|
+
include Template::Choice
|
36
|
+
|
37
|
+
class OtherName
|
38
|
+
include Template::Sequence
|
39
|
+
|
40
|
+
asn1_object_id :type
|
41
|
+
asn1_any :value, tag: 0, tagging: :EXPLICIT
|
42
|
+
end
|
43
|
+
|
44
|
+
class EDIPartyName
|
45
|
+
include Template::Sequence
|
46
|
+
|
47
|
+
asn1_template :name_assigner, DirectoryString, tag: 0, tagging: :IMPLICIT, optional: true
|
48
|
+
asn1_template :party_name, DirectoryString, tag: 1, tagging: :IMPLICIT
|
49
|
+
end
|
50
|
+
|
51
|
+
asn1_template OtherName, tag: 0, tagging: :IMPLICIT
|
52
|
+
asn1_ia5_string tag: 1, tagging: :IMPLICIT
|
53
|
+
asn1_ia5_string tag: 2, tagging: :IMPLICIT
|
54
|
+
asn1_any tag: 3, tagging: :IMPLICIT
|
55
|
+
asn1_template DistinguishedName, tag: 4, tagging: :EXPLICIT
|
56
|
+
asn1_template EDIPartyName, tag: 5, tagging: :IMPLICIT
|
57
|
+
asn1_ia5_string tag: 6, tagging: :IMPLICIT
|
58
|
+
asn1_octet_string tag: 7, tagging: :IMPLICIT
|
59
|
+
asn1_object_id tag: 8, tagging: :IMPLICIT
|
60
|
+
end
|
61
|
+
|
62
|
+
class AlgorithmIdentifier
|
63
|
+
include Template::Sequence
|
64
|
+
|
65
|
+
asn1_object_id :algorithm
|
66
|
+
asn1_any :params, optional: true
|
67
|
+
|
68
|
+
def self.algorithm_null_params(name)
|
69
|
+
AlgorithmIdentifier.new do |alg|
|
70
|
+
alg.algorithm = name
|
71
|
+
alg.params = Krypt::ASN1::Null.new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
class << self; private :algorithm_null_params; end
|
75
|
+
|
76
|
+
MD5 = algorithm_null_params('1.2.840.113549.2.5')
|
77
|
+
RIPEMD160 = algorithm_null_params('1.3.36.3.2.1')
|
78
|
+
SHA1 = algorithm_null_params('1.3.14.3.2.26')
|
79
|
+
SHA224 = algorithm_null_params('2.16.840.1.101.3.4.2.4')
|
80
|
+
SHA256 = algorithm_null_params('2.16.840.1.101.3.4.2.1')
|
81
|
+
SHA384 = algorithm_null_params('2.16.840.1.101.3.4.2.2')
|
82
|
+
SHA512 = algorithm_null_params('2.16.840.1.101.3.4.2.3')
|
83
|
+
|
84
|
+
RSA = algorithm_null_params('1.2.840.113549.1.1.1')
|
85
|
+
|
86
|
+
RSA_MD5 = algorithm_null_params('1.2.840.113549.1.1.4')
|
87
|
+
RSA_SHA1 = algorithm_null_params('1.2.840.113549.1.1.5')
|
88
|
+
RSA_SHA224 = algorithm_null_params('1.2.840.113549.1.1.14')
|
89
|
+
RSA_SHA256 = algorithm_null_params('1.2.840.113549.1.1.11')
|
90
|
+
RSA_SHA384 = algorithm_null_params('1.2.840.113549.1.1.12')
|
91
|
+
RSA_SHA512 = algorithm_null_params('1.2.840.113549.1.1.13')
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
@@ -0,0 +1,257 @@
|
|
1
|
+
module Krypt::ASN1
|
2
|
+
module Template
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
module Sequence
|
6
|
+
include Template
|
7
|
+
def self.included(base)
|
8
|
+
Template.init_cons_definition(base) do
|
9
|
+
:SEQUENCE
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Set
|
15
|
+
include Template
|
16
|
+
def self.included(base)
|
17
|
+
Template.init_cons_definition(base) do
|
18
|
+
:SET
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Choice
|
24
|
+
include Template
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
Template._mod_included_callback(base)
|
28
|
+
definition = {
|
29
|
+
codec: :CHOICE,
|
30
|
+
layout: []
|
31
|
+
}
|
32
|
+
base.instance_variable_set(:@definition, definition)
|
33
|
+
base.extend Template::ChoiceAccessor
|
34
|
+
base.extend Template::ChoiceDefinitions
|
35
|
+
base.extend Template::Parser
|
36
|
+
base.asn1_attr_accessor :value, :@value
|
37
|
+
base.asn1_attr_accessor :tag, :@tag
|
38
|
+
base.asn1_attr_accessor :type, :@type
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module SequenceOf
|
43
|
+
include Template
|
44
|
+
def self.included(base)
|
45
|
+
Template.init_cons_of_definition(base) do
|
46
|
+
:SEQUENCE_OF
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module SetOf
|
52
|
+
include Template
|
53
|
+
def self.included(base)
|
54
|
+
Template.init_cons_of_definition(base) do
|
55
|
+
:SET_OF
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self.init_cons_definition(base)
|
63
|
+
_mod_included_callback(base)
|
64
|
+
definition = {
|
65
|
+
codec: yield,
|
66
|
+
layout: [],
|
67
|
+
min_size: 0
|
68
|
+
}
|
69
|
+
base.instance_variable_set(:@definition, definition)
|
70
|
+
base.extend Template::Accessor
|
71
|
+
base.extend Template::ConstructedDefinitions
|
72
|
+
base.extend Template::Parser
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.init_cons_of_definition(base)
|
76
|
+
_mod_included_callback(base)
|
77
|
+
definition = { codec: yield }
|
78
|
+
base.instance_variable_set(:@definition, definition)
|
79
|
+
base.extend Template::Accessor
|
80
|
+
base.extend Template::ConstructedOfDefinitions
|
81
|
+
base.extend Template::Parser
|
82
|
+
base.asn1_attr_accessor :value, :@value
|
83
|
+
end
|
84
|
+
|
85
|
+
module GeneralDefinitions
|
86
|
+
def init_methods
|
87
|
+
declare_prim(:asn1_boolean, Krypt::ASN1::BOOLEAN)
|
88
|
+
declare_prim(:asn1_integer, Krypt::ASN1::INTEGER)
|
89
|
+
declare_prim(:asn1_bit_string, Krypt::ASN1::BIT_STRING)
|
90
|
+
declare_prim(:asn1_octet_string, Krypt::ASN1::OCTET_STRING)
|
91
|
+
declare_prim(:asn1_null, Krypt::ASN1::NULL)
|
92
|
+
declare_prim(:asn1_object_id, Krypt::ASN1::OBJECT_ID)
|
93
|
+
declare_prim(:asn1_enumerated, Krypt::ASN1::ENUMERATED)
|
94
|
+
declare_prim(:asn1_utf8_string, Krypt::ASN1::UTF8_STRING)
|
95
|
+
declare_prim(:asn1_numeric_string, Krypt::ASN1::NUMERIC_STRING)
|
96
|
+
declare_prim(:asn1_printable_string, Krypt::ASN1::PRINTABLE_STRING)
|
97
|
+
declare_prim(:asn1_t61_string, Krypt::ASN1::T61_STRING)
|
98
|
+
declare_prim(:asn1_videotex_string, Krypt::ASN1::VIDEOTEX_STRING)
|
99
|
+
declare_prim(:asn1_ia5_string, Krypt::ASN1::IA5_STRING)
|
100
|
+
declare_prim(:asn1_utc_time, Krypt::ASN1::UTC_TIME)
|
101
|
+
declare_prim(:asn1_generalized_time, Krypt::ASN1::GENERALIZED_TIME)
|
102
|
+
declare_prim(:asn1_graphic_string, Krypt::ASN1::GRAPHIC_STRING)
|
103
|
+
declare_prim(:asn1_iso64_string, Krypt::ASN1::ISO64_STRING)
|
104
|
+
declare_prim(:asn1_general_string, Krypt::ASN1::GENERAL_STRING)
|
105
|
+
declare_prim(:asn1_universal_string, Krypt::ASN1::UNIVERSAL_STRING)
|
106
|
+
declare_prim(:asn1_bmp_string, Krypt::ASN1::BMP_STRING)
|
107
|
+
|
108
|
+
declare_special_typed(:asn1_template, :TEMPLATE)
|
109
|
+
declare_special_typed(:asn1_sequence_of, :SEQUENCE_OF)
|
110
|
+
declare_special_typed(:asn1_set_of, :SET_OF)
|
111
|
+
|
112
|
+
declare_any
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.add_to_definition(klass, deff)
|
116
|
+
cur_def = klass.instance_variable_get(:@definition)
|
117
|
+
cur_def[:layout] << deff
|
118
|
+
codec = cur_def[:codec]
|
119
|
+
if codec == :SEQUENCE || codec == :SET
|
120
|
+
increase_min_size(cur_def, deff[:options])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def self.increase_min_size(cur_def, cur_opts)
|
127
|
+
cur_opts ||= {}
|
128
|
+
default = cur_opts[:default]
|
129
|
+
optional = cur_opts[:optional]
|
130
|
+
unless optional || default != nil
|
131
|
+
cur_def[:min_size] += 1
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
module Accessor
|
137
|
+
def asn1_attr_accessor(name, iv_name)
|
138
|
+
define_method name do
|
139
|
+
_get_callback(iv_name)
|
140
|
+
end
|
141
|
+
define_method "#{name.to_s}=".to_sym do |value|
|
142
|
+
_set_callback(iv_name, value)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
module ChoiceAccessor
|
148
|
+
def asn1_attr_accessor(name, iv_name)
|
149
|
+
define_method name do
|
150
|
+
_get_callback_choice(iv_name)
|
151
|
+
end
|
152
|
+
define_method "#{name.to_s}=".to_sym do |value|
|
153
|
+
_set_callback_choice(iv_name, value)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
module ChoiceDefinitions
|
159
|
+
extend GeneralDefinitions
|
160
|
+
class << self
|
161
|
+
define_method :declare_prim do |meth, type|
|
162
|
+
define_method meth do |opts=nil|
|
163
|
+
GeneralDefinitions.add_to_definition(self, {
|
164
|
+
codec: :PRIMITIVE,
|
165
|
+
type: type,
|
166
|
+
options: opts
|
167
|
+
})
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
define_method :declare_special_typed do |meth, codec|
|
172
|
+
define_method meth do |type, opts=nil|
|
173
|
+
raise ArgumentError.new "Type must not be nil" if type == nil
|
174
|
+
GeneralDefinitions.add_to_definition(self, {
|
175
|
+
codec: codec,
|
176
|
+
type: type,
|
177
|
+
options: opts
|
178
|
+
})
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
define_method :declare_any do
|
183
|
+
define_method :asn1_any do |opts=nil|
|
184
|
+
GeneralDefinitions.add_to_definition(self, {
|
185
|
+
codec: :ANY,
|
186
|
+
type: Krypt::ASN1::ASN1Data,
|
187
|
+
options: opts
|
188
|
+
})
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
init_methods
|
194
|
+
end
|
195
|
+
|
196
|
+
module ConstructedDefinitions
|
197
|
+
extend GeneralDefinitions
|
198
|
+
class << self
|
199
|
+
define_method :declare_prim do |meth, type|
|
200
|
+
define_method meth do |name, opts=nil|
|
201
|
+
raise ArgumentError.new "Name must not be nil" if name == nil
|
202
|
+
iv_name = ('@' + name.to_s).to_sym
|
203
|
+
asn1_attr_accessor name, iv_name
|
204
|
+
|
205
|
+
GeneralDefinitions.add_to_definition(self, {
|
206
|
+
codec: :PRIMITIVE,
|
207
|
+
type: type,
|
208
|
+
name: iv_name,
|
209
|
+
options: opts
|
210
|
+
})
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
define_method :declare_special_typed do |meth, codec|
|
215
|
+
define_method meth do |name, type, opts=nil|
|
216
|
+
raise ArgumentError.new "Name must not be nil" if name == nil
|
217
|
+
raise ArgumentError.new "Type must not be nil" if type == nil
|
218
|
+
iv_name = ('@' + name.to_s).to_sym
|
219
|
+
asn1_attr_accessor name, iv_name
|
220
|
+
|
221
|
+
GeneralDefinitions.add_to_definition(self, {
|
222
|
+
codec: codec,
|
223
|
+
type: type,
|
224
|
+
name: iv_name,
|
225
|
+
options: opts
|
226
|
+
})
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
define_method :declare_any do
|
231
|
+
define_method :asn1_any do |name, opts=nil|
|
232
|
+
raise ArgumentError.new "Name must not be nil" if name == nil
|
233
|
+
iv_name = ('@' + name.to_s).to_sym
|
234
|
+
asn1_attr_accessor name, iv_name
|
235
|
+
|
236
|
+
GeneralDefinitions.add_to_definition(self, {
|
237
|
+
codec: :ANY,
|
238
|
+
type: Krypt::ASN1::ASN1Data,
|
239
|
+
name: iv_name,
|
240
|
+
options: opts
|
241
|
+
})
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
init_methods
|
247
|
+
end
|
248
|
+
|
249
|
+
module ConstructedOfDefinitions
|
250
|
+
def asn1_type(type)
|
251
|
+
raise ArgumentError.new "Type must not be nil" if type == nil
|
252
|
+
cur_def = instance_variable_get(:@definition)
|
253
|
+
cur_def[:type] = type
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|