File: base64.rb

package info (click to toggle)
ruby-kdl 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: ruby: 6,667; yacc: 72; sh: 5; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 467 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'base64'

module KDL
  module Types
    class Base64 < Value
      RGX = /^[A-Za-z0-9+\/=]+$/.freeze

      def self.call(value, type = 'base64')
        return nil unless value.is_a? ::KDL::Value::String

        unless RGX.match?(value.value)
            raise ArgumentError, "invalid base64: #{value.value}"
        end

        data = ::Base64.decode64(value.value)
        new(data, type: type)
      end
    end
    MAPPING['base64'] = Base64
  end
end