Class: LibSSH::Key

Inherits:
Object
  • Object
show all
Defined in:
ext/libssh_ruby/key.c,
lib/libssh/key.rb,
ext/libssh_ruby/key.c

Overview

Wrapper for ssh_key struct in libssh.

Instance Method Summary collapse

Constructor Details

#initializeObject

Initialize an empty key.

See Also:

Since:

  • 0.1.0



36
37
38
39
40
41
# File 'ext/libssh_ruby/key.c', line 36

static VALUE m_initialize(VALUE self) {
  KeyHolder *holder;
  TypedData_Get_Struct(self, KeyHolder, &key_type, holder);
  holder->key = ssh_key_new();
  return self;
}

Instance Method Details

#private?Boolean

Check if the key is a private key.

Returns:

  • (Boolean)

See Also:

Since:

  • 0.1.0



107
108
109
# File 'ext/libssh_ruby/key.c', line 107

static VALUE m_private_p(VALUE self) {
  return ssh_key_is_private(libssh_ruby_key_holder(self)->key) ? Qtrue : Qfalse;
}

#public?Boolean

Check if the key is a public key.

Returns:

  • (Boolean)

See Also:

Since:

  • 0.1.0



97
98
99
# File 'ext/libssh_ruby/key.c', line 97

static VALUE m_public_p(VALUE self) {
  return ssh_key_is_public(libssh_ruby_key_holder(self)->key) ? Qtrue : Qfalse;
}

#sha1String

Return the hash in SHA1 form.

Since:

  • 0.1.0



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'ext/libssh_ruby/key.c', line 55

static VALUE m_sha1(VALUE self) {
  KeyHolder *holder;
  unsigned char *c_hash;
  size_t len;
  VALUE hash;

  holder = libssh_ruby_key_holder(self);
  ssh_get_publickey_hash(holder->key, SSH_PUBLICKEY_HASH_SHA1, &c_hash, &len);
  hash = rb_str_new((char *)c_hash, len);
  ssh_clean_pubkey_hash(&c_hash);

  return hash;
}

#sha1_hexString

Return the hash in SHA1 in hexadecimal notation.

Returns:

  • (String)

See Also:

Since:

  • 0.1.0



9
10
11
# File 'lib/libssh/key.rb', line 9

def sha1_hex
  sha1.unpack('H*')[0].each_char.each_slice(2).map(&:join).join(':')
end

#typeFixnum

Return the type of a SSH key.

Returns:

  • (Fixnum)

See Also:

Since:

  • 0.1.0



75
76
77
# File 'ext/libssh_ruby/key.c', line 75

static VALUE m_type(VALUE self) {
  return INT2FIX(ssh_key_type(libssh_ruby_key_holder(self)->key));
}

#type_strString

Return the type of a SSH key in string format.

Returns:

  • (String)

See Also:

Since:

  • 0.1.0



86
87
88
89
# File 'ext/libssh_ruby/key.c', line 86

static VALUE m_type_str(VALUE self) {
  return rb_str_new_cstr(
      ssh_key_type_to_char(ssh_key_type(libssh_ruby_key_holder(self)->key)));
}