Class: Linzer::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/linzer/signature.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#labelObject (readonly)

Returns the value of attribute label.



13
14
15
# File 'lib/linzer/signature.rb', line 13

def label
  @label
end

#metadataObject (readonly) Also known as: components

Returns the value of attribute metadata.



13
14
15
# File 'lib/linzer/signature.rb', line 13

def 
  @metadata
end

#parametersObject (readonly)

Returns the value of attribute parameters.



13
14
15
# File 'lib/linzer/signature.rb', line 13

def parameters
  @parameters
end

#valueObject (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, options = {})
  basic_validate headers
  headers.transform_keys!(&:downcase)
  validate headers

  input = parse_field(headers, "signature-input")
  reject_multiple_signatures if input.size > 1 && options[:label].nil?
  label = options[: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_hObject



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