Sha256: edc9f75fcfc5bc1518685e6b50545761eb90fd183887fa1b55757071371ae29d

Contents?: true

Size: 715 Bytes

Versions: 15

Compression:

Stored size: 715 Bytes

Contents

module RASN1
  module Types

    # ASN.1 Boolean
    # @author Sylvain Daubert
    class Boolean < Primitive
      TAG = 0x01

      private

      def value_to_der
        [@value ? 0xff : 0x00].pack('C')
      end

      def der_to_value(der, ber: false)
        unless der.size == 1
          raise ASN1Error, "tag #@name: BOOLEAN should have a length of 1"
        end

        bool = der.unpack('C').first
        case bool
        when 0
          @value = false
        when 0xff
          @value = true
        else
          if ber
            @value = true
          else
            raise ASN1Error, "tag #@name: bad value 0x%02x for BOOLEAN" % bool
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rasn1-0.6.8 lib/rasn1/types/boolean.rb
rasn1-0.6.7 lib/rasn1/types/boolean.rb
rasn1-0.6.6 lib/rasn1/types/boolean.rb
rasn1-0.6.5 lib/rasn1/types/boolean.rb
rasn1-0.6.4 lib/rasn1/types/boolean.rb
rasn1-0.6.3 lib/rasn1/types/boolean.rb
rasn1-0.6.2 lib/rasn1/types/boolean.rb
rasn1-0.6.1 lib/rasn1/types/boolean.rb
rasn1-0.6.0 lib/rasn1/types/boolean.rb
rasn1-0.5.0 lib/rasn1/types/boolean.rb
rasn1-0.4.0 lib/rasn1/types/boolean.rb
rasn1-0.3.1 lib/rasn1/types/boolean.rb
rasn1-0.3.0 lib/rasn1/types/boolean.rb
rasn1-0.2.0 lib/rasn1/types/boolean.rb
rasn1-0.1.0 lib/rasn1/types/boolean.rb