Class: CryptoGost::Signature

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

Overview

DigitalSignature

Author:

  • WildDima

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r:, s:) ⇒ Signature

Returns a new instance of Signature.



19
20
21
22
# File 'lib/crypto_gost/signature.rb', line 19

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

Instance Attribute Details

#rObject (readonly)

Returns the value of attribute r.



8
9
10
# File 'lib/crypto_gost/signature.rb', line 8

def r
  @r
end

#sObject (readonly)

Returns the value of attribute s.



8
9
10
# File 'lib/crypto_gost/signature.rb', line 8

def s
  @s
end

Class Method Details

.decode(sign) ⇒ Object



11
12
13
14
15
16
# File 'lib/crypto_gost/signature.rb', line 11

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

Instance Method Details

#encodeObject



24
25
26
27
28
29
30
# File 'lib/crypto_gost/signature.rb', line 24

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