Sha256: 19ca8106e5b8ebfe6fbf97a9580d8f45bd8b6aa21c61b6288f2e3491e676c895

Contents?: true

Size: 733 Bytes

Versions: 2

Compression:

Stored size: 733 Bytes

Contents

# frozen_string_literal: true

module RASN1
  module Types
    # ASN.1 Printable String
    # @author Sylvain Daubert
    class PrintableString < OctetString
      # PrintableString tag value
      TAG = 19

      # Get ASN.1 type
      # @return [String]
      def self.type
        'PrintableString'
      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 =~ /([^a-zA-Z0-9 '=\(\)\+,\-\.\/:\?])/
          raise ASN1Error, "PRINTABLE 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/printable_string.rb
rasn1-0.7.0 lib/rasn1/types/printable_string.rb