Class: EC::Signature

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, s) ⇒ Signature

Returns a new instance of Signature.



24
25
26
# File 'lib/elliptic/signature.rb', line 24

def initialize(r, s)
  @r, @s = r, s
end

Instance Attribute Details

#rObject (readonly)

Returns the value of attribute r.



23
24
25
# File 'lib/elliptic/signature.rb', line 23

def r
  @r
end

#sObject (readonly)

Returns the value of attribute s.



23
24
25
# File 'lib/elliptic/signature.rb', line 23

def s
  @s
end

Class Method Details

.decode_base64(str) ⇒ Object Also known as: from_base64



12
13
14
# File 'lib/elliptic/signature.rb', line 12

def self.decode_base64( str )
  decode_der( Base64.decode64( str ) )
end

.decode_der(der) ⇒ Object Also known as: from_der



5
6
7
8
9
10
# File 'lib/elliptic/signature.rb', line 5

def self.decode_der( der )
  asn1 = OpenSSL::ASN1.decode( der )
  r = asn1.value[0].value.to_i
  s = asn1.value[1].value.to_i
  new(r, s)
end

Instance Method Details

#to_base64Object



36
37
38
# File 'lib/elliptic/signature.rb', line 36

def to_base64
   Base64.encode64( to_der ).gsub("\n", '' )
end

#to_derObject



28
29
30
31
32
33
34
# File 'lib/elliptic/signature.rb', line 28

def to_der
  asn1 = OpenSSL::ASN1::Sequence.new [
      OpenSSL::ASN1::Integer.new( @r ),
      OpenSSL::ASN1::Integer.new( @s ),
    ]
  asn1.to_der
end