Module: Binenc::Java::ASN1Object

Includes:
BinaryObject, DataConversion, TR::CondUtils
Included in:
ASN1Binary, ASN1DateTime, ASN1Integer, ASN1OID, ASN1Sequence, ASN1String
Defined in:
lib/binenc/asn1_engine/asn1_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DataConversion

#from_b64, #from_hex, included, #to_b64, #to_b64_mime, #to_bin, #to_hex, #to_java_bytes, #to_str

Instance Attribute Details

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/binenc/asn1_engine/asn1_object.rb', line 13

def value
  @value
end

Class Method Details

.decode(bin) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/binenc/asn1_engine/asn1_object.rb', line 23

def self.decode(bin)
  if not_empty?(bin)

    begin
      ais = ::Java::OrgBouncycastleAsn1::ASN1InputStream.new(to_java_bytes(bin))
      obj = ais.readObject

      case obj
      when ::Java::OrgBouncycastleAsn1::DERBitString
        ASN1Binary.new(obj.bytes)
      when ::Java::OrgBouncycastleAsn1::DERUTF8String
        ASN1String.new(obj.to_s)
      when ::Java::OrgBouncycastleAsn1::ASN1Integer
        ASN1Integer.new(obj.value)
      when ::Java::OrgBouncycastleAsn1::DERSequence, ::Java::OrgBouncycastleAsn1::DLSequence
        ASN1Sequence.new(obj.to_a)
      when ::Java::OrgBouncycastleAsn1::ASN1GeneralizedTime
        ASN1DateTime.new(obj.date)
      when ::Java::OrgBouncycastleAsn1::ASN1ObjectIdentifier
        ASN1OID.new(obj.id)
      else
        raise BinencEngineException, "Unhandled ASN1 object '#{obj.class}'"
      end
    rescue ::Java::JavaIo::IOException => ex
      raise BinencDecodingError, ex
    end

  else
    raise BinencEngineException, "Cannot decode empty binary #{bin}"
  end
end

Instance Method Details

#initialize(*args, &block) ⇒ Object



15
16
17
# File 'lib/binenc/asn1_engine/asn1_object.rb', line 15

def initialize(*args, &block)
  @value = args.first
end

#is_equal?(val) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/binenc/asn1_engine/asn1_object.rb', line 19

def is_equal?(val)
  @value == val
end