Class: Linzer::Signature
- Inherits:
-
Object
- Object
- Linzer::Signature
- Defined in:
- lib/linzer/signature.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#metadata ⇒ Object
(also: #components)
readonly
Returns the value of attribute metadata.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#value ⇒ Object
(also: #bytes)
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(metadata, value, label, parameters = {}) ⇒ Signature
constructor
A new instance of Signature.
- #to_h ⇒ Object
Constructor Details
#initialize(metadata, value, label, parameters = {}) ⇒ Signature
Returns a new instance of Signature.
5 6 7 8 9 10 11 |
# File 'lib/linzer/signature.rb', line 5 def initialize(, value, label, parameters = {}) @metadata = .clone.freeze @value = value.clone.freeze @parameters = parameters.clone.freeze @label = label.clone.freeze freeze end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
13 14 15 |
# File 'lib/linzer/signature.rb', line 13 def label @label end |
#metadata ⇒ Object (readonly) Also known as: components
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/linzer/signature.rb', line 13 def @metadata end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
13 14 15 |
# File 'lib/linzer/signature.rb', line 13 def parameters @parameters end |
#value ⇒ Object (readonly) Also known as: bytes
Returns the value of attribute value.
13 14 15 |
# File 'lib/linzer/signature.rb', line 13 def value @value end |
Class Method Details
.build(headers, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/linzer/signature.rb', line 29 def build(headers, = {}) basic_validate headers headers.transform_keys!(&:downcase) validate headers input = parse_field(headers, "signature-input") reject_multiple_signatures if input.size > 1 && [:label].nil? label = [:label] || input.keys.first signature = parse_field(headers, "signature") fail_with_signature_not_found label unless signature.key?(label) raw_signature = signature[label].value .force_encoding(Encoding::ASCII_8BIT) fail_due_invalid_components unless input[label].value.respond_to?(:each) ascii = Encoding::US_ASCII components = input[label].value.map { |c| c.value.encode(ascii) } parameters = input[label].parameters new(components, raw_signature, label, parameters) end |
Instance Method Details
#to_h ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/linzer/signature.rb', line 17 def to_h { "signature" => Starry.serialize({label => value}), "signature-input" => Starry.serialize({label => Starry::InnerList.new(components, parameters)}) } end |