Class: LibSSH::Key
- Inherits:
-
Object
- Object
- LibSSH::Key
- Defined in:
- lib/libssh/key.rb,
ext/libssh_ruby/key.c
Instance Method Summary collapse
- #initialize ⇒ Object constructor
-
#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 ⇒ Object
-
#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
31 32 33 34 35 36 |
# File 'ext/libssh_ruby/key.c', line 31
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
96 97 98 |
# File 'ext/libssh_ruby/key.c', line 96
static VALUE m_public_p(VALUE self) {
return ssh_key_is_public(libssh_ruby_key_holder(self)->key) ? Qtrue : Qfalse;
}
|
#sha1 ⇒ String
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'ext/libssh_ruby/key.c', line 51
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 ⇒ Object
5 6 7 |
# File 'lib/libssh/key.rb', line 5 def sha1_hex sha1.unpack('H*')[0].each_char.each_slice(2).map(&:join).join(':') end |
#type ⇒ Fixnum
72 73 74 |
# File 'ext/libssh_ruby/key.c', line 72
static VALUE m_type(VALUE self) {
return INT2FIX(ssh_key_type(libssh_ruby_key_holder(self)->key));
}
|
#type_str ⇒ String
84 85 86 87 |
# File 'ext/libssh_ruby/key.c', line 84
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)));
}
|