Sha256: 10d8f54fd1b756301d048ffe65475aea1c19450d356ee019d0891888c32288bb

Contents?: true

Size: 726 Bytes

Versions: 4

Compression:

Stored size: 726 Bytes

Contents

# frozen_string_literal: true

module RASN1
  module Types
    # ASN.1 Printable String
    # @author Sylvain Daubert
    class PrintableString < OctetString
      # PrintableString id value
      ID = 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
        m = @value.to_s.match(%r{([^a-zA-Z0-9 '=()+,\-./:?])})
        raise ASN1Error, "PRINTABLE STRING #{@name}: invalid character: '#{m[1]}'" if m
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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