Class: Moxml::Signature::Algorithms::CanonicalizationBase
- Inherits:
-
Object
- Object
- Moxml::Signature::Algorithms::CanonicalizationBase
- Defined in:
- lib/moxml/signature/algorithms/canonicalization_base.rb
Overview
Base class for canonicalization algorithms.
Subclasses declare identifier "http://..." and implement #engine
(returning a Moxml::C14n::* walker). Canonicalizers operate on a
Moxml::Node subtree and return UTF-8 octets.
Canonicalization algorithms can also be used as transforms per spec §6.6.1. The base class provides the #transform method that adapts the canonicalize interface to the transform pipeline.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#identifier_uri ⇒ Object
readonly
Returns the value of attribute identifier_uri.
-
#inclusive_namespaces ⇒ Object
readonly
Returns the value of attribute inclusive_namespaces.
-
#with_comments ⇒ Object
readonly
Returns the value of attribute with_comments.
Class Method Summary collapse
- .for_uri(uri, **opts) ⇒ Object
- .identifier(uri) ⇒ Object
-
.input_type ⇒ Object
Canonicalization presents the transform interface (spec §6.6.1).
- .output_type ⇒ Object
Instance Method Summary collapse
- #canonicalize(node) ⇒ Object
-
#initialize(identifier_uri: nil, with_comments: nil, inclusive_namespaces: [], context: nil, **_unused) ⇒ CanonicalizationBase
constructor
context:is required when this algorithm is used as a transform so that octet-stream input can be parsed with the same adapter the caller used for the rest of the document. -
#transform(input) ⇒ Object
Adapt to the transform interface (spec §6.6.1).
Constructor Details
#initialize(identifier_uri: nil, with_comments: nil, inclusive_namespaces: [], context: nil, **_unused) ⇒ CanonicalizationBase
context: is required when this algorithm is used as a transform
so that octet-stream input can be parsed with the same adapter
the caller used for the rest of the document.
40 41 42 43 44 45 46 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 40 def initialize(identifier_uri: nil, with_comments: nil, inclusive_namespaces: [], context: nil, **_unused) @identifier_uri = identifier_uri @with_comments = with_comments.nil? ? uri_has_comments?(identifier_uri) : with_comments @inclusive_namespaces = inclusive_namespaces || [] @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
34 35 36 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 34 def context @context end |
#identifier_uri ⇒ Object (readonly)
Returns the value of attribute identifier_uri.
34 35 36 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 34 def identifier_uri @identifier_uri end |
#inclusive_namespaces ⇒ Object (readonly)
Returns the value of attribute inclusive_namespaces.
34 35 36 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 34 def inclusive_namespaces @inclusive_namespaces end |
#with_comments ⇒ Object (readonly)
Returns the value of attribute with_comments.
34 35 36 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 34 def with_comments @with_comments end |
Class Method Details
.for_uri(uri, **opts) ⇒ Object
29 30 31 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 29 def for_uri(uri, **opts) new(identifier_uri: uri, **opts) end |
.identifier(uri) ⇒ Object
25 26 27 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 25 def identifier(uri) Algorithms.register(:canonicalization, uri, self) end |
.input_type ⇒ Object
Canonicalization presents the transform interface (spec §6.6.1). Input: octet stream or node-set. Output: octet stream.
21 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 21 def input_type; :nodeset; end |
.output_type ⇒ Object
23 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 23 def output_type; :octets; end |
Instance Method Details
#canonicalize(node) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 48 def canonicalize(node) engine.canonicalize( node, with_comments: @with_comments, inclusive_namespaces: @inclusive_namespaces, ) end |
#transform(input) ⇒ Object
Adapt to the transform interface (spec §6.6.1). Octet-stream input is parsed using the same Moxml::Context the caller used; this preserves the byte-exact invariant across adapters.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/moxml/signature/algorithms/canonicalization_base.rb', line 59 def transform(input) return canonicalize(input) if input.is_a?(::Moxml::Node) if context.nil? raise TransformError, "canonicalization transform requires a context to parse " \ "octet-stream input; none was provided" end parsed = context.parse(input.to_s) canonicalize(parsed.root) end |