Sha256: b278ffe7093c0c2f967e15c8e70841f2d27b3a3e7f267d8d91b79b632ca7ba91

Contents?: true

Size: 699 Bytes

Versions: 2

Compression:

Stored size: 699 Bytes

Contents

# frozen_string_literal: true

module RASN1
  module Types
    # ASN.1 Numeric String
    # @author Sylvain Daubert
    class NumericString < OctetString
      # NumericString tag value
      TAG = 18

      # Get ASN.1 type
      # @return [String]
      def self.type
        'NumericString'
      end

      private

      def value_to_der
        check_characters
        @value.to_s.force_encoding('BINARY')
      end

      def der_to_value(der, ber:false)
        super
        check_characters
      end

      def check_characters
        if @value.to_s =~ /([^0-9 ])/
          raise ASN1Error, "NUMERIC STRING #{@name}: invalid character: '#{$1}'"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rasn1-0.7.1 lib/rasn1/types/numeric_string.rb
rasn1-0.7.0 lib/rasn1/types/numeric_string.rb