Sha256: 6df3bf6526f7d2fa0ac49ba44d6999675aaa1337ff1fec37cfb1239cba2058d3

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

module RASN1
  module Types

    describe Set do
        before(:each) do
          @set = Set.new(:set)
          @bool = Boolean.new(:bool, default: true)
          @int = Integer.new(:int)
          @bs = BitString.new(:bs)
          @set.value = [@bool, @int, @bs]

          @no_bool_der = binary("\x30\x09\x02\x01\x2A\x03\x04\x01\x01\x04\x06")
          @der = binary("\x30\x0c\x01\x01\x00\x02\x01\x2A\x03\x04\x01\x01\x04\x06")
        end
        
      describe '.type' do
        it 'gets ASN.1 type' do
          expect(Set.type).to eq('SET')
        end
      end

      describe '#initialize' do
        it 'creates an Set with default values' do
          set = Set.new(:set)
          expect(set).to be_constructed
          expect(set).to_not be_optional
          expect(set.asn1_class).to eq(:universal)
          expect(set.default).to eq(nil)
        end
      end

      describe '#to_der' do
        it 'generates a DER string' do
          @int.value = 42
          @bs.value = [1,4,6].pack('C3')
          @bs.bit_length = 23
          expect(@set.to_der).to eq(@no_bool_der)

          @bool.value = false
          expect(@set.to_der).to eq(@der)
        end
      end

      describe '#parse!' do
        it 'parses DER string' do
          @set.parse!(@der)
          expect(@bool.value).to be(false)
          expect(@int.value).to eq(42)
          expect(@bs.value).to eq([1,4,6].pack('C3'))
          expect(@bs.bit_length).to eq(23)

          @set.parse!(@no_bool_der)
          expect(@bool.value).to be(true)
          expect(@int.value).to eq(42)
          expect(@bs.value).to eq([1,4,6].pack('C3'))
          expect(@bs.bit_length).to eq(23)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rasn1-0.3.1 lib/rasn1/types/set_spec.rb
rasn1-0.3.0 lib/rasn1/types/set_spec.rb
rasn1-0.2.0 lib/rasn1/types/set_spec.rb
rasn1-0.1.0 lib/rasn1/types/set_spec.rb