Sha256: 33724778fb50a928519bcf4665e33d276a1347f2fda24eba06793b0b78962ed5

Contents?: true

Size: 676 Bytes

Versions: 4

Compression:

Stored size: 676 Bytes

Contents

# frozen_string_literal: true

module RASN1
  module Types
    # ASN.1 Numeric String
    # @author Sylvain Daubert
    class NumericString < OctetString
      # NumericString id value
      ID = 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
        raise ASN1Error, "NUMERIC STRING #{@name}: invalid character: '#{$1}'" if @value.to_s =~ /([^0-9 ])/
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rasn1-0.11.0 lib/rasn1/types/numeric_string.rb
rasn1-0.10.0 lib/rasn1/types/numeric_string.rb
rasn1-0.9.0 lib/rasn1/types/numeric_string.rb
rasn1-0.8.0 lib/rasn1/types/numeric_string.rb