Class: Moxml::Signature::Algorithms::Base64Transform

Inherits:
TransformBase
  • Object
show all
Defined in:
lib/moxml/signature/algorithms/base64_transform.rb

Overview

Base64 decode transform (W3C ยง6.6.2).

Input: octets or nodeset. For nodeset, logically applies self::text(), sorts nodes by document order, concatenates string values, then decodes. Output: octets.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TransformBase

identifier, #initialize

Constructor Details

This class inherits a constructor from Moxml::Signature::Algorithms::TransformBase

Class Method Details

.input_typeObject



16
# File 'lib/moxml/signature/algorithms/base64_transform.rb', line 16

def self.input_type; :octets; end

.output_typeObject



17
# File 'lib/moxml/signature/algorithms/base64_transform.rb', line 17

def self.output_type; :octets; end

Instance Method Details

#transform(input) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/moxml/signature/algorithms/base64_transform.rb', line 19

def transform(input)
  text = input.is_a?(Array) ? input.map { |n| text_of(n) }.join : input.to_s
  stripped = text.gsub(/\s+/, "")
  Base64.strict_decode64(stripped)
rescue ArgumentError => e
  raise TransformError.new(
    "base64 decode failed: #{e.message}",
    algorithm: self.class.identifier_uri,
  )
end