rasn2 0.16.0

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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +4 -0
  4. data/lib/rasn1/errors.rb +55 -0
  5. data/lib/rasn1/helpers/colorize.rb +76 -0
  6. data/lib/rasn1/model.rb +831 -0
  7. data/lib/rasn1/schema_parser.rb +470 -0
  8. data/lib/rasn1/tracer.rb +200 -0
  9. data/lib/rasn1/types/any.rb +98 -0
  10. data/lib/rasn1/types/base.rb +675 -0
  11. data/lib/rasn1/types/bit_string.rb +100 -0
  12. data/lib/rasn1/types/bmp_string.rb +22 -0
  13. data/lib/rasn1/types/boolean.rb +57 -0
  14. data/lib/rasn1/types/choice.rb +158 -0
  15. data/lib/rasn1/types/constrained.rb +51 -0
  16. data/lib/rasn1/types/constructed.rb +51 -0
  17. data/lib/rasn1/types/enumerated.rb +44 -0
  18. data/lib/rasn1/types/generalized_time.rb +156 -0
  19. data/lib/rasn1/types/ia5_string.rb +21 -0
  20. data/lib/rasn1/types/integer.rb +166 -0
  21. data/lib/rasn1/types/null.rb +43 -0
  22. data/lib/rasn1/types/numeric_string.rb +41 -0
  23. data/lib/rasn1/types/object_id.rb +64 -0
  24. data/lib/rasn1/types/octet_string.rb +52 -0
  25. data/lib/rasn1/types/primitive.rb +13 -0
  26. data/lib/rasn1/types/printable_string.rb +42 -0
  27. data/lib/rasn1/types/sequence.rb +105 -0
  28. data/lib/rasn1/types/sequence_of.rb +199 -0
  29. data/lib/rasn1/types/set.rb +28 -0
  30. data/lib/rasn1/types/set_of.rb +18 -0
  31. data/lib/rasn1/types/tag.rb +189 -0
  32. data/lib/rasn1/types/universal_string.rb +22 -0
  33. data/lib/rasn1/types/utc_time.rb +67 -0
  34. data/lib/rasn1/types/utf8_string.rb +21 -0
  35. data/lib/rasn1/types/visible_string.rb +30 -0
  36. data/lib/rasn1/types.rb +149 -0
  37. data/lib/rasn1/value_notation.rb +256 -0
  38. data/lib/rasn1/version.rb +6 -0
  39. data/lib/rasn1/wrapper.rb +279 -0
  40. data/lib/rasn1.rb +51 -0
  41. metadata +123 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1b52ab2b6b1a8019f3ae996d875ef09869cf715c2a58cce73c58bd8ba6a50b95
4
+ data.tar.gz: ebd0936fdb3a8921c97c33d18b2938bd461fd525a6991dd52a45b65be552bb2c
5
+ SHA512:
6
+ metadata.gz: 3e57fb8bf6ebd8e2d9df9558613cac061f8f73344ee6fcf73ae72abb0946313503a6f4df24d5487a2859fd51c4dc9d4d74391570adaddd7b33ec2ce1d93ac3ca
7
+ data.tar.gz: e5d1dc4e78a2e7d4bd1830ae1f0bc7d4eae17aaccdbf6708f42ef7cacc3ff6719ff83cb6d9f732971534199b18b533343f1ba16135229870673c308ce18f6267
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Sylvain Daubert
4
+ Copyright (c) 2024 LemonTree55
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ***/!\ WARNING:***
2
+ RASN1 moved to https://codeberg.org/lemontree55/rasn1
3
+
4
+ This repository wil no more be updated.
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RASN1
4
+ # Base error class
5
+ class Error < StandardError; end
6
+
7
+ # ASN.1 encoding/decoding error
8
+ class ASN1Error < Error; end
9
+
10
+ # ASN.1 class error
11
+ class ClassError < Error
12
+ # @return [String]
13
+ def message
14
+ "Tag class should be a symbol among: #{Types::Base::CLASSES.keys.join(', ')}"
15
+ end
16
+ end
17
+
18
+ # Enumerated error
19
+ class EnumeratedError < Error; end
20
+
21
+ # CHOICE error: {Types::Choice#chosen} not set
22
+ class ChoiceError < RASN1::Error
23
+ # @param [Types::Base] object
24
+ def initialize(object)
25
+ @object = object
26
+ super()
27
+ end
28
+
29
+ # @return [String]
30
+ def message
31
+ "CHOICE #{@object.name}: #chosen not set"
32
+ end
33
+ end
34
+
35
+ # Exception raised when a constraint is not verified on a constrained type.
36
+ # @version 0.11.0
37
+ # @author Sylvain Daubert
38
+ class ConstraintError < Error
39
+ # @param [Types::Base] object
40
+ def initialize(object)
41
+ @object = object
42
+ super()
43
+ end
44
+
45
+ # @return [String]
46
+ def message
47
+ "Constraint not verified on #{@object.inspect}"
48
+ end
49
+ end
50
+
51
+ # Exception raised when model validation fails
52
+ # @since 0.12.0
53
+ class ModelValidationError < Error
54
+ end
55
+ end
@@ -0,0 +1,76 @@
1
+ module RASN1
2
+ module Helpers
3
+ module Colorize
4
+ def parens_hex(input, padding=2)
5
+ input = input.is_a?(Integer) ? ("0x%0#{padding}x")% input : "0x#{input}"
6
+ "#{colorize('(').webgray}#{colorize(input).blue}#{colorize(')').webgray}"
7
+ end
8
+
9
+ def int_with_hex(input, raw_value=nil)
10
+ if raw_value
11
+ "#{colorize(input).blue} #{parens_hex(raw_value)}"
12
+ else
13
+ "#{colorize(input).blue} #{parens_hex(input)}"
14
+ end
15
+
16
+ end
17
+
18
+ def brace_surround(input)
19
+ "#{colorize('[').webgray} #{input} #{colorize(']').webgray}"
20
+ end
21
+
22
+ def colorize_class(name, tag_id=nil)
23
+ if tag_id
24
+ "#{colorize(name).bold.yellow} #{parens_hex(tag_id)}"
25
+ else
26
+ colorize(name).bold.yellow
27
+ end
28
+ end
29
+
30
+ def colorize_id(id, tag_class=nil)
31
+ id = id.strip if id.is_a? String
32
+ tag_class = tag_class.strip if tag_class.is_a? String
33
+ if tag_class && tag_class != ''
34
+ brace_surround("#{colorize_class(tag_class)} #{colorize(id).bold.green}")
35
+ else
36
+ brace_surround(colorize(id).bold.green)
37
+ end
38
+
39
+ end
40
+
41
+ def length_specifier(data_length, encoded_length = nil)
42
+ encoded_length = data_length if encoded_length.nil?
43
+ "#{colorize('len:').gray} #{colorize(data_length).blue} #{parens_hex(encoded_length)}"
44
+ end
45
+
46
+ def colorize_name(name)
47
+ colorize(name).bold.white
48
+ end
49
+
50
+ def colorize_attribute(attribute)
51
+ colorize(attribute).bold.magenta
52
+ end
53
+
54
+ def colorize_default(value)
55
+ colorize(value).green.bold
56
+ end
57
+
58
+ def colorize_nil(name = 'NONE')
59
+ colorize(name).red.bold
60
+ end
61
+
62
+ def colorize_enum(name, raw_value)
63
+ raw_value = raw_value.unpack1('H*') if raw_value.is_a?(String)
64
+ "#{colorize_class(name)} #{parens_hex(raw_value)}"
65
+ end
66
+
67
+ def colorize_bool(value, raw_value)
68
+ if value
69
+ "#{colorize('TRUE').bold.green} #{parens_hex(raw_value)}"
70
+ else
71
+ "#{colorize('FALSE').bold.red} #{parens_hex(raw_value)}"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end