Class: Orthrus::SSH::DSAPrivateKey

Inherits:
PrivateKey show all
Includes:
DSA
Defined in:
lib/orthrus/ssh/dsa.rb

Instance Attribute Summary

Attributes inherited from Key

#comment, #key, #source

Instance Method Summary collapse

Methods included from DSA

#initialize, #public_identity, #type

Methods inherited from Key

#==, #dsa?, #fingerprint, #initialize, #inspect, #rsa?

Instance Method Details

#sign(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/orthrus/ssh/dsa.rb', line 33

def sign(data)
  sig = super data

  a1sig = OpenSSL::ASN1.decode sig

  sig_r = a1sig.value[0].value.to_s(2)
  sig_s = a1sig.value[1].value.to_s(2)

  if sig_r.length > 20 || sig_s.length > 20
    raise OpenSSL::PKey::DSAError, "bad sig size"
  end

  sig_r = "\0" * ( 20 - sig_r.length ) + sig_r if sig_r.length < 20
  sig_s = "\0" * ( 20 - sig_s.length ) + sig_s if sig_s.length < 20
  return sig_r + sig_s
end