Class: LibSSH::Key
- Inherits:
-
Object
- Object
- LibSSH::Key
- 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
-
#initialize ⇒ Object
constructor
Initialize an empty key.
-
#private? ⇒ Boolean
Check if the key is a private key.
-
#public? ⇒ Boolean
Check if the key is a public key.
-
#sha1 ⇒ String
Return the hash in SHA1 form.
-
#sha1_hex ⇒ String
Return the hash in SHA1 in hexadecimal notation.
-
#type ⇒ Fixnum
Return the type of a SSH key.
-
#type_str ⇒ String
Return the type of a SSH key in string format.
Constructor Details
#initialize ⇒ Object
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
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
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;
}
|
#sha1 ⇒ String
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_hex ⇒ String
Return the hash in SHA1 in hexadecimal notation.
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 |
#type ⇒ Fixnum
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_str ⇒ String
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)));
}
|