Class: Minisign::Signature

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

Overview

Parse a .minisig file’s contents

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Signature

Returns a new instance of Signature.

Examples:

Minisign::Signature.new(File.read('test/example.txt.minisig'))

Parameters:

  • str (String)

    The contents of the .minisig file



9
10
11
# File 'lib/minisign/signature.rb', line 9

def initialize(str)
  @lines = str.split("\n")
end

Instance Method Details

#key_idString

Returns the key id.

Examples:

Minisign::Signature.new(File.read('test/example.txt.minisig')).key_id
#=> "E86FECED695E8E0"

Returns:

  • (String)

    the key id



17
18
19
# File 'lib/minisign/signature.rb', line 17

def key_id
  encoded_signature[2..9].bytes.map { |c| c.to_s(16) }.reverse.join.upcase
end

#signatureString

Returns the global signature.

Returns:

  • (String)

    the global signature



35
36
37
# File 'lib/minisign/signature.rb', line 35

def signature
  encoded_signature[10..]
end

#to_sString

Returns The signature that can be written to a file.

Returns:

  • (String)

    The signature that can be written to a file



40
41
42
# File 'lib/minisign/signature.rb', line 40

def to_s
  "#{@lines.join("\n")}\n"
end

#trusted_commentString

Returns the trusted comment.

Examples:

Minisign::Signature.new(File.read('test/example.txt.minisig')).trusted_comment
#=> "timestamp:1653934067\tfile:example.txt\thashed"

Returns:

  • (String)

    the trusted comment



25
26
27
# File 'lib/minisign/signature.rb', line 25

def trusted_comment
  @lines[2].split('trusted comment: ')[1]
end

#trusted_comment_signatureString

Returns the signature for the trusted comment.

Returns:

  • (String)

    the signature for the trusted comment



30
31
32
# File 'lib/minisign/signature.rb', line 30

def trusted_comment_signature
  Base64.decode64(@lines[3])
end