Class: MooTool::Models::ECCSignature

Inherits:
Object
  • Object
show all
Includes:
Helpers::IMG4
Defined in:
lib/mootool/models/ecc_signature.rb

Overview

Elliptic Curve Cryptography Signature

Constant Summary

Constants included from Helpers::IMG4

Helpers::IMG4::DECODE_TAGS, Helpers::IMG4::FIRMWARE_TAGS, Helpers::IMG4::HASH_LENGTHS, Helpers::IMG4::KEY_INSTANCE_TAGS, Helpers::IMG4::KVP_TAGS, Helpers::IMG4::OCTET_TAGS, Helpers::IMG4::SEQUENCE_TAGS, Helpers::IMG4::SIGNATURE_TAGS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::IMG4

#construct, #construct_object, #decode_construct, parse_4cc

Constructor Details

#initialize(signature) ⇒ ECCSignature

Returns a new instance of ECCSignature.



11
12
13
14
15
# File 'lib/mootool/models/ecc_signature.rb', line 11

def initialize(signature)
  @value = signature
  @values = construct(OpenSSL::ASN1.decode(signature))
  @r, @s = @values
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/mootool/models/ecc_signature.rb', line 9

def value
  @value
end

Class Method Details

.create(signature) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mootool/models/ecc_signature.rb', line 21

def self.create(signature)
  size = signature.is_a?(MooTool::Models::Digest) ? signature.value.size : signature.size
  if size > 128
    # RSA Signature
    signature.hint = 'RSASignature' if signature.respond_to?(:hint)
    signature
  else
    value = signature.respond_to?(:value) ? signature.value : signature
    MooTool::Models::ECCSignature.new(value)
  end
end

Instance Method Details

#to_hObject



17
18
19
# File 'lib/mootool/models/ecc_signature.rb', line 17

def to_h
  { r: @r, s: @s }
end