diff options
Diffstat (limited to 'lib/asn1kit/types/relative_oid.rb')
-rw-r--r-- | lib/asn1kit/types/relative_oid.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/asn1kit/types/relative_oid.rb b/lib/asn1kit/types/relative_oid.rb new file mode 100644 index 0000000..8485010 --- /dev/null +++ b/lib/asn1kit/types/relative_oid.rb @@ -0,0 +1,67 @@ +# coding: ASCII-8BIT + +class ASN1Kit::RelativeOID < ASN1Kit::Type + asn1_tag :IMPLICIT, :UNIVERSAL, 13 + asn1_alias "RELATIVE-OID" + + attr_reader :components + + def initialize(components) + @components = components + end + + def dot_notation + @components.join(".") + end + + def self.from_dot_notation(string) + new(string.split(".").map { |s| Integer(s) }) + end + + def to_der + content = @components.pack("w*") + der_header(content.bytesize) << content + end + + private def inspect_inner + "{ #{@components.join(" ")} }" + end + + def cast_to(type) + return type.new(@components) if type <= ASN1Kit::RelativeOID + super + end + + def ==(other) + other.is_a?(ASN1Kit::RelativeOID) && @components == other.components + end +end + +module ASN1Kit::Internal::CompileRelativeOID + refine ASN1Kit::RelativeOID.singleton_class do + def _new_internal(arys) + obj = allocate + obj.instance_variable_set(:@_compile_arys, arys) + obj + end + end + + refine ASN1Kit::RelativeOID do + def _compile_fixup(state) + arys = remove_instance_variable(:@_compile_arys) + + components = [] + arys.each do |ary| + case ary + when ASN1Kit::Internal::UnresolvedValue + rel_oid = ary.unwrap(state) + components.concat(rel_oid.components) + else + components.concat(ary.map { |v| v.unwrap_as_number(state) }) + end + end + + @components = components + end + end +end |