Class: Net::SSH::Authentication::ED25519::PrivKey

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/authentication/ed25519.rb

Constant Summary collapse

CipherFactory =
Net::SSH::Transport::CipherFactory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ PrivKey

Returns a new instance of PrivKey.

Raises:

  • (ArgumentError)


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/net/ssh/authentication/ed25519.rb', line 230

def initialize(buffer)
  pk = buffer.read_string
  sk = buffer.read_string
  _comment = buffer.read_string

  ED25519.validate_key_bytes!(pk, "public key", KEY_BYTES)
  ED25519.validate_key_bytes!(sk, "private key field", PRIVATE_KEY_BYTES)

  private_key_bytes = sk[0, KEY_BYTES]
  raise ArgumentError, "Ed25519 private key does not include matching public key" unless sk[KEY_BYTES, KEY_BYTES] == pk

  @sign_key = ED25519.new_private_key(private_key_bytes)
  raise ArgumentError, "Ed25519 public key does not match private key" unless @sign_key.raw_public_key == pk

  @public_key_bytes = pk.dup.force_encoding('BINARY')
  @private_key_bytes = private_key_bytes.dup.force_encoding('BINARY')
end

Instance Attribute Details

#sign_key ⇒ Object (readonly)

Returns the value of attribute sign_key.



228
229
230
# File 'lib/net/ssh/authentication/ed25519.rb', line 228

def sign_key
  @sign_key
end

Class Method Details

.read(data, password) ⇒ Object



280
281
282
# File 'lib/net/ssh/authentication/ed25519.rb', line 280

def self.read(data, password)
  OpenSSHPrivateKeyLoader.read(data, password)
end

Instance Method Details

#private_key_bytes ⇒ Object



272
273
274
# File 'lib/net/ssh/authentication/ed25519.rb', line 272

def private_key_bytes
  @private_key_bytes.dup
end

#private_key_bytes_for_agent ⇒ Object



276
277
278
# File 'lib/net/ssh/authentication/ed25519.rb', line 276

def private_key_bytes_for_agent
  private_key_bytes + public_key_bytes
end

#public_key ⇒ Object



260
261
262
# File 'lib/net/ssh/authentication/ed25519.rb', line 260

def public_key
  PubKey.new(public_key_bytes)
end

#public_key_bytes ⇒ Object



268
269
270
# File 'lib/net/ssh/authentication/ed25519.rb', line 268

def public_key_bytes
  @public_key_bytes.dup
end

#ssh_do_sign(data, sig_alg = nil) ⇒ Object



264
265
266
# File 'lib/net/ssh/authentication/ed25519.rb', line 264

def ssh_do_sign(data, sig_alg = nil)
  ED25519.sign(@sign_key, data)
end

#ssh_signature_type ⇒ Object



256
257
258
# File 'lib/net/ssh/authentication/ed25519.rb', line 256

def ssh_signature_type
  ssh_type
end

#ssh_type ⇒ Object



252
253
254
# File 'lib/net/ssh/authentication/ed25519.rb', line 252

def ssh_type
  "ssh-ed25519"
end

#to_blob ⇒ Object



248
249
250
# File 'lib/net/ssh/authentication/ed25519.rb', line 248

def to_blob
  public_key.to_blob
end