Class: DerParse::Node
- Inherits:
-
Object
- Object
- DerParse::Node
- Defined in:
- lib/derparse/node.rb,
lib/derparse/node/nil.rb,
lib/derparse/node/null.rb,
lib/derparse/node/integer.rb,
lib/derparse/node/sequence.rb,
lib/derparse/node/octet_string.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Integer, Nil, Null, OctetString, Sequence
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_length ⇒ Object
readonly
Returns the value of attribute data_length.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#length_length ⇒ Object
readonly
Returns the value of attribute length_length.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#rest ⇒ Object
readonly
Returns the value of attribute rest.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#tag_class ⇒ Object
readonly
Returns the value of attribute tag_class.
-
#tag_length ⇒ Object
readonly
Returns the value of attribute tag_length.
Class Method Summary collapse
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #constructed? ⇒ Boolean
- #der_length ⇒ Object
- #first_child ⇒ Object
- #header_length ⇒ Object
-
#initialize(der, depth: 0, offset: 0) ⇒ Node
constructor
A new instance of Node.
- #next_node ⇒ Object
- #primitive? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(der, depth: 0, offset: 0) ⇒ Node
Returns a new instance of Node.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/derparse/node.rb', line 17 def initialize(der, depth: 0, offset: 0) @depth, @offset = depth, offset @tag = @tag_class = @constructed = @tag_length = @data_length = @length_length, @data = nil @complete = true begin r = parse_type(der) r = parse_length(r) @rest = parse_data(r) rescue IncompleteDer @complete = false @rest = "" end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def data @data end |
#data_length ⇒ Object (readonly)
Returns the value of attribute data_length.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def data_length @data_length end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def depth @depth end |
#length_length ⇒ Object (readonly)
Returns the value of attribute length_length.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def length_length @length_length end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def offset @offset end |
#rest ⇒ Object (readonly)
Returns the value of attribute rest.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def rest @rest end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def tag @tag end |
#tag_class ⇒ Object (readonly)
Returns the value of attribute tag_class.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def tag_class @tag_class end |
#tag_length ⇒ Object (readonly)
Returns the value of attribute tag_length.
15 16 17 |
# File 'lib/derparse/node.rb', line 15 def tag_length @tag_length end |
Class Method Details
.factory(der, *args) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/derparse/node.rb', line 5 def self.factory(der, *args) klass_name = DerParse::Node.constants.find do |const| DerParse::Node.const_get(const).handles?(der) end klass = klass_name.nil? ? DerParse::Node : const_get(klass_name) klass.new(der, *args) end |
Instance Method Details
#complete? ⇒ Boolean
56 57 58 |
# File 'lib/derparse/node.rb', line 56 def complete? @complete end |
#constructed? ⇒ Boolean
48 49 50 |
# File 'lib/derparse/node.rb', line 48 def constructed? @constructed end |
#der_length ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/derparse/node.rb', line 32 def der_length if data_length.nil? || header_length.nil? nil else data_length + header_length end end |
#first_child ⇒ Object
68 69 70 |
# File 'lib/derparse/node.rb', line 68 def first_child DerParse::Node::Nil.new end |
#header_length ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/derparse/node.rb', line 40 def header_length if tag_length.nil? || length_length.nil? nil else tag_length + length_length end end |
#next_node ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/derparse/node.rb', line 60 def next_node if @rest.empty? DerParse::Node::Nil.new else DerParse::Node.factory(@rest) end end |
#primitive? ⇒ Boolean
52 53 54 |
# File 'lib/derparse/node.rb', line 52 def primitive? !constructed? end |
#value ⇒ Object
72 73 74 |
# File 'lib/derparse/node.rb', line 72 def value raise IncompatibleDatatypeError, "No known way to render tag #{@tag} into a value" end |