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)


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/net/ssh/authentication/ed25519.rb', line 225

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_keyObject (readonly)

Returns the value of attribute sign_key.



223
224
225
# File 'lib/net/ssh/authentication/ed25519.rb', line 223

def sign_key
  @sign_key
end

Class Method Details

.read(data, password) ⇒ Object



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

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

Instance Method Details

#private_key_bytesObject



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

def private_key_bytes
  @private_key_bytes.dup
end

#private_key_bytes_for_agentObject



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

def private_key_bytes_for_agent
  private_key_bytes + public_key_bytes
end

#public_keyObject



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

def public_key
  PubKey.new(public_key_bytes)
end

#public_key_bytesObject



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

def public_key_bytes
  @public_key_bytes.dup
end

#ssh_do_sign(data, sig_alg = nil) ⇒ Object



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

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

#ssh_signature_typeObject



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

def ssh_signature_type
  ssh_type
end

#ssh_typeObject



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

def ssh_type
  "ssh-ed25519"
end

#to_blobObject



243
244
245
# File 'lib/net/ssh/authentication/ed25519.rb', line 243

def to_blob
  public_key.to_blob
end